1
0
forked from s421507/eOSP2
This commit is contained in:
Krzysztof Strzelecki 2019-12-07 15:25:53 +01:00
commit 98196dae50
12 changed files with 265 additions and 34 deletions

View File

@ -8,7 +8,9 @@ use App\operations;
use App\operationsMembers; use App\operationsMembers;
use App\vehicle; use App\vehicle;
use App\operationsDrivers; use App\operationsDrivers;
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;
@ -17,8 +19,12 @@ class operationsController extends Controller
// //
public function create(){ public function create(){
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)
->leftJoin('users', 'operations.commanderID', '=', 'users.id')
->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.name', 'users.surname')
->get();
return view('operation'); return view('operation', ["operations" => $operations]);
} else{ } else{
return view('operation'); return view('operation');
} }
@ -26,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();
@ -37,8 +41,34 @@ class operationsController extends Controller
public function editForm(){ public function editForm($id){
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();
$operationMembers = DB::table('operationsMembers')->where('operationID', '=', $id)->get();
// $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();
$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) {
// return view('operationEdit', ["operation" => $operation], ["fireFighters" => $fireFighters], ["operationMembers" => $operationMembers] );
return View::make('/operationEdit')->with(compact('fireFighters','operation', 'operationMembers', 'vehicles'));
// } else{
// return "Brak dostepu";
// }
} else{
return view('unit');
}
} }
public function store(){ public function store(){
@ -49,12 +79,16 @@ class operationsController extends Controller
'operationDangerType' => 'required', 'operationDangerType' => 'required',
'operationDescription' => 'required', 'operationDescription' => 'required',
'operationLeader' => 'required', 'operationLeader' => 'required',
'operationDriver' => 'required', 'operationDriver.*' => 'required',
'operationVehicle.*' => 'required',
'attendance.*' => 'required',
'transport.*' => 'required',
], ],
[ [
'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,
@ -63,12 +97,121 @@ class operationsController extends Controller
'dangerType' => $request-> operationDangerType, 'dangerType' => $request-> operationDangerType,
'description' => $request-> operationDescription, 'description' => $request-> operationDescription,
'commanderID' => $request-> operationLeader, 'commanderID' => $request-> operationLeader,
'fireStationID' => auth()->user()->fireStationID,
]); ]);
// Add trucks
$operationDriver = $request ->operationDriver;
$operationVehicle = $request -> operationVehicle;
for($count = 0; $count < count($operationDriver); $count++){
$operationsTrucks = operationsTrucks::create([
'operationID' => $operations->id,
'truckID' => $operationDriver[$count],
'driverID' => $operationVehicle[$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();
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' => $operations->id,
'memberID' => $attendance[$count],
'privateTransport' => $privateTransport,
]);
};
}
return operationsController::create(); return operationsController::create();
} }
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

@ -9,5 +9,5 @@ class operations extends Model
// //
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $fillable = ['operationDate', 'location', 'target', 'dangerType', 'description', 'commanderID', 'driverID']; protected $fillable = ['fireStationID', 'operationDate', 'location', 'target', 'dangerType', 'description', 'commanderID'];
} }

View File

@ -8,6 +8,7 @@ class operationsMembers extends Model
{ {
// //
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $table = 'operationsMembers';
protected $fillable = ['operationID', 'memberID']; protected $fillable = ['operationID', 'memberID', 'privateTransport'];
} }

View File

@ -8,6 +8,7 @@ class operationsTrucks extends Model
{ {
// //
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $table = 'operationsTrucks';
protected $fillable = ['operationID', 'truckID']; protected $fillable = ['operationID', 'truckID', 'driverID'];
} }

View File

@ -21,7 +21,6 @@ class CreateOperationsTable extends Migration
$table->string('dangerType', 100); $table->string('dangerType', 100);
$table->string('description'); $table->string('description');
$table->integer('commanderID'); $table->integer('commanderID');
$table->integer('driverID');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -17,6 +17,7 @@ class CreateOperationsTrucksTable extends Migration
$table->increments('id'); $table->increments('id');
$table->integer('operationID'); $table->integer('operationID');
$table->integer('truckID'); $table->integer('truckID');
$table->integer('driverID');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -17,6 +17,7 @@ class CreateOperationsMembersTable extends Migration
$table->increments('id'); $table->increments('id');
$table->integer('operationID'); $table->integer('operationID');
$table->integer('memberID'); $table->integer('memberID');
$table->boolean('privateTransport');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFireStationIDColumnToOperationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('operations', function (Blueprint $table) {
//
$table->integer('fireStationID');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('operations', function (Blueprint $table) {
//
});
}
}

View File

@ -11,6 +11,34 @@
@section('center-area') @section('center-area')
@parent @parent
Strona w budowie @if( auth()->check())
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
<table class='firefighterViewTable'>
<tr class='table-header'>
<td>Data</td>
<td>Miejsce</td>
<td>Cel</td>
<td>Rodzaj zagrożenia</td>
<td>Dowódca</td>
</tr>
@foreach($operations as $operation)
<tr>
<td id="operationDate{{ $operation->id }}">{{ $operation->operationDate }}</td>
<td id="operationLocation{{ $operation->id }}">{{ $operation->location }}</td>
<td id="operationTarget{{ $operation->id }}">{{ $operation->target }}</td>
<td id="operationDangerType{{ $operation->id }}">{{ $operation->dangerType }}</td>
<td id="operationCommander{{ $operation->id }}">{{$operation->name}} {{$operation->surname}}</td>
<td><a href="{{ URL::asset('wyjazdy/edit/'.$operation->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td>
</tr>
@endforeach
</table>"
@endif
@else
Brak autoryzacji
@endif
@stop @stop

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">
@ -52,23 +52,42 @@
<div class=form-group"> <div class=form-group">
<div id="drivers"> <div id="drivers">
<label for="location">Kierowca:</label> {{-- <label for="location">Kierowca:</label>--}}
<select name="operationDriver" class="form-control"> {{-- <select name="operationDriver" class="form-control">--}}
<option value="">--- Wybierz kierowcę ---</option> {{-- <option value="">--- Wybierz kierowcę ---</option>--}}
@foreach ($fireFighters as $fireFighter) {{-- @foreach ($fireFighters as $fireFighter)--}}
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option> {{-- <option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>--}}
@endforeach {{-- @endforeach--}}
</select> {{-- </select>--}}
<label for="location">Pojazd:</label> {{-- <label for="location">Pojazd:</label>--}}
<select name="operationVehicle" class="form-control"> {{-- <select name="operationVehicle" class="form-control">--}}
<option value="">--- Wybierz pojazd ---</option> {{-- <option value="">--- Wybierz pojazd ---</option>--}}
@foreach ($vehicles as $vehicle) {{-- @foreach ($vehicles as $vehicle)--}}
<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option> {{-- <option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>--}}
@endforeach {{-- @endforeach--}}
</select> {{-- </select>--}}
</div> </div>
</div> </div>
<div class="form-group">
<table>
<tr>
<td>Imię i nazwisko: </td><td></td><td>Obecność:</td><td></td><td>Transport własny:</td>
</tr>
@php
$i = 0;
@endphp
@foreach($fireFighters as $fireFighterChecklist)
<tr>
<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>
@php
$i++;
@endphp
@endforeach
</table>
</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,31 +12,33 @@
@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 }}">
<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="{{$operation->operationDate}}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Miejsce akcji:</label> <label for="location">Miejsce akcji:</label>
<input type="text" class="form-control" id="operationLocation" name="operationLocation"> <input type="text" class="form-control" id="operationLocation" name="operationLocation" value="{{ $operation->location }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Cel wyjazdu:</label> <label for="location">Cel wyjazdu:</label>
<input type="text" class="form-control" id="operationTarget" name="operationTarget"> <input type="text" class="form-control" id="operationTarget" name="operationTarget" value="{{ $operation->target }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Rodzaj zagrożenia:</label> <label for="location">Rodzaj zagrożenia:</label>
<input type="text" class="form-control" id="operationDangerType" name="operationDangerType"> <input type="text" class="form-control" id="operationDangerType" name="operationDangerType" value="{{ $operation->dangerType }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Opis akcji:</label> <label for="location">Opis akcji:</label>
<textarea class="form-control" id="'operationDescription" name="operationDescription">Enter text here...</textarea> <textarea class="form-control" id="'operationDescription" name="operationDescription">{{ $operation->description }}</textarea>
</div> </div>
<div class=form-group"> <div class=form-group">
@ -44,7 +46,7 @@
<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>
@ -72,14 +74,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}}" {{$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++;
@ -89,6 +91,7 @@
</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

@ -33,6 +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('/register', 'RegistrationController@create'); Route::get('/register', 'RegistrationController@create');
Route::post('/register', 'RegistrationController@store'); Route::post('/register', 'RegistrationController@store');