dodanie widoku Pojazdy

This commit is contained in:
Krzysztof Strzelecki 2019-11-17 17:08:02 +01:00
parent cb9965cd95
commit 2a8b8a6d6f
7 changed files with 464 additions and 39 deletions

View File

@ -0,0 +1,149 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\vehicle;
use DB;
use Carbon\Carbon; // formatowanie daty
function formatDate($date)
{
$fdate = Carbon::parse($date);
return $fdate;
}
class VehiclesController extends Controller
{
public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID)
->get();
return view("vehicles", ["vehicles" => $vehicles]);
} else{
return view('vehicles');
}
}
public function addForm(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
return view('vehiclesAdd');
} else return view("login");
}
public function editForm($id)
{
if(auth()->user() != null && auth()->user()->fireStationID != null )
{
//$userFireStation = auth()->user()->fireStationID;
//$fireFighterFireStation = DB::table('users')->where("id", $id)->value('fireStationID');
//$fireStationCreatorId = DB::table('fireStations')->where("id", $userFireStation)->value('creatorID');
$vehicle = DB::table('vehicles')->where("id", $id)->first();
return view('vehiclesEdit', ["vehicle" => $vehicle]);
}
else
return "Brak dostepu";
}
public function store(){
$this->validate(request(), [
'name' => 'required',
'productionYear' => 'digits:4',
'foamAgent' => 'numeric',
'enginePower' => 'numeric',
'crewNumber' => 'numeric',
'mass' => 'numeric',
'chassisPoductionYear' => 'numeric',
//dokończyć! Wypytać Adriana które mają być required
],
[
'required' => ':attribute jest wymagany(e).',
'numeric' => ':attribute zawiera tylko cyfry.',
'digits' => ':attribute musi składać się z :digits cyfr.',
]);
$request = request();
$vehicle = vehicle::create([
'fireStationID' => auth()->user()->fireStationID,
'name' => $request-> name,
'codename' => $request-> codename,
'brand' => $request-> brand,
'registrationNumber' => $request-> registrationNumber,
'productionYear' => $request-> productionYear,
'examExpirationDate' => formatDate($request-> examExpirationDate),
'insuranceExpirationDate' => formatDate($request-> insuranceExpirationDate),
'driveType' => $request-> driveType,
'chassisType' => $request-> chassisType,
'bodyProducer' => $request-> bodyProducer,
'crewNumber' => $request-> crewNumber,
'foamAgent' => $request-> foamAgent,
'enginePower' => $request-> enginePower,
'mass' => $request-> mass,
'chassisNumber' => $request-> chassisNumber,
'engineNumber' => $request-> engineNumber,
'fuelType' => $request-> fuelType,
'chassisPoductionYear' => $request-> chassisPoductionYear,
'entryIntoServiceDate' => formatDate($request-> entryIntoServiceDate),
'fireEnginePumpDescription' => $request-> fireEnginePumpDescription,
]);
return redirect()->to('/pojazdy');
}
public function update(){
$this->validate(request(), [
'name' => 'required',
'productionYear' => 'digits:4',
'foamAgent' => 'numeric',
'enginePower' => 'numeric',
'crewNumber' => 'numeric',
'mass' => 'numeric',
'chassisPoductionYear' => 'numeric',
//dokończyć! Wypytać Adriana które mają być required
],
[
'required' => ':attribute jest wymagany(e).',
'numeric' => ':attribute zawiera tylko cyfry.',
'digits' => ':attribute musi składać się z :digits cyfr.',
]);
$request = request();
$vehicle = vehicle::find( $request->vehicleID);
$vehicle-> name = $request-> name;
$vehicle-> codename = $request-> codename;
$vehicle-> brand = $request-> brand;
$vehicle-> registrationNumber = $request-> registrationNumber;
$vehicle-> productionYear = $request-> productionYear;
$vehicle-> examExpirationDate = formatDate($request-> examExpirationDate);
$vehicle-> insuranceExpirationDate = formatDate($request-> insuranceExpirationDate);
$vehicle-> driveType = $request-> driveType;
$vehicle-> chassisType = $request-> chassisType;
$vehicle-> bodyProducer = $request-> bodyProducer;
$vehicle-> crewNumber = $request-> crewNumber;
$vehicle-> foamAgent = $request-> foamAgent;
$vehicle-> enginePower = $request-> enginePower;
$vehicle-> mass = $request-> mass;
$vehicle-> chassisNumber = $request-> chassisNumber;
$vehicle-> engineNumber = $request-> engineNumber;
$vehicle-> fuelType = $request-> fuelType;
$vehicle-> chassisPoductionYear = $request-> chassisPoductionYear;
$vehicle-> entryIntoServiceDate = formatDate($request-> entryIntoServiceDate);
$vehicle-> fireEnginePumpDescription = $request-> fireEnginePumpDescription;
$vehicle->save();
return VehiclesController::create();
}
}

16
app/vehicle.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class vehicle extends Model
{
protected $primaryKey = 'id';
protected $table = 'vehicles';
protected $fillable = [
'fireStationID','name', 'codename', 'brand', 'registrationNumber', 'productionYear', 'examExpirationDate', 'insuranceExpirationDate', 'driveType', 'chassisType', 'bodyProducer', 'crewNumber', 'foamAgent', 'enginePower', 'mass', 'chassisNumber', 'engineNumber', 'fuelType', 'chassisPoductionYear', 'entryIntoServiceDate', 'fireEnginePumpDescription', 'created_at', 'updated_at'
];
}

View File

@ -15,12 +15,13 @@ class CreateVehiclesTable extends Migration
{ {
Schema::create('vehicles', function (Blueprint $table) { Schema::create('vehicles', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('fireStationID');
$table->string('name', 45); $table->string('name', 45);
$table->string('codename', 45); $table->string('codename', 45);
$table->string('brand',45); $table->string('brand',45);
$table->string('registrationNumber', 15); $table->string('registrationNumber', 15);
$table->integer('productionYear'); $table->integer('productionYear');
$table->date('ExaminationExpirationDate'); $table->date('examExpirationDate'); //Data ważności przegladu
$table->date('insuranceExpirationDate'); $table->date('insuranceExpirationDate');
$table->string('driveType',45); //układ napędowy $table->string('driveType',45); //układ napędowy
$table->string('chassisType',45); //typ podwozia $table->string('chassisType',45); //typ podwozia
@ -29,12 +30,13 @@ class CreateVehiclesTable extends Migration
$table->integer('foamAgent'); //Ilość środka pianotwórczego w litrach $table->integer('foamAgent'); //Ilość środka pianotwórczego w litrach
$table->integer('enginePower'); //Moc silnika w kW $table->integer('enginePower'); //Moc silnika w kW
$table->integer('mass'); //Masa całkowita pojazdu $table->integer('mass'); //Masa całkowita pojazdu
$table->integer('chassisNumber'); $table->string('chassisNumber');
$table->integer('engineNumber'); $table->string('engineNumber');
$table->string('fuelType',45); $table->string('fuelType',45);
$table->integer('chassisPoductionYear'); $table->integer('chassisPoductionYear');
$table->date('entryIntoServiceDate'); $table->date('entryIntoServiceDate');
$table->string('fireEnginePumpDescription');// Opis autopompy $table->string('fireEnginePumpDescription');// Opis autopompy
$table->timestamps();
}); });
} }

View File

@ -3,7 +3,7 @@
@section('left-menu') @section('left-menu')
@parent @parent
<ul> <ul>
<li>Dodaj<img src="img/left_menu_icon/add.png"></li> <a href="/pojazdy/add"><li>Dodaj<img src="img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="img/left_menu_icon/edit.png"></li> <li>Edytuj<img src="img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="img/left_menu_icon/delete.png"></li> <li>Usuń<img src="img/left_menu_icon/delete.png"></li>
<li>Zawieś<img src="img/left_menu_icon/suspended.png"></li> <li>Zawieś<img src="img/left_menu_icon/suspended.png"></li>
@ -12,40 +12,46 @@
@section('center-area') @section('center-area')
@parent @parent
@if( auth()->check())
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
<table class='firefighterViewTable'> <table class='firefighterViewTable'>
<tr class='table-header'> <tr class='table-header'>
<td>LP</td> <td>LP</td>
<td>Typ Pojazdu</td> <td>Typ Pojazdu</td>
<td>Marka</td> <td>Marka</td>
<td>Nr rej.</td> <td>Nr rej.</td>
<td>Kryptonim</td> <td>Kryptonim</td>
<td>Rok Produkcji</td> <td>Rok Produkcji</td>
<td>Rodzaj napędu</td> <td>Rodzaj napędu</td>
<td>Przegląd</td> <td>Przegląd</td>
<td>OC</td> <td>OC</td>
</tr> @php
<tr> $lp=0 // liczba porządkowa
<td>1</td> @endphp
<td>GBA</td> @foreach($vehicles as $vehicle)
<td>Jelcz 005</td> @php
<td>PKN 131</td> $lp = $lp + 1
<td>368-81</td> @endphp
<td>1987</td> <tr>
<td>4x4</td> <td>{{ $lp }}</td>
<td>23.04.2020r</td> <td id="name{{ $vehicle->id }}">{{ $vehicle->name }}</td>
<td>24.04.2020r</td> <td id="brand{{ $vehicle->id }}">{{ $vehicle->brand }}</td>
</tr> <td id="registrationNumber{{ $vehicle->id }}">{{ $vehicle->registrationNumber }}</td>
<tr> <td id="codename{{ $vehicle->id }}">{{ $vehicle->codename }}</td>
<td>2</td> <td id="productionYear{{ $vehicle->id }}">{{ $vehicle->productionYear }}</td>
<td>Ponton</td> <td id="driveType{{ $vehicle->id }}">{{ $vehicle->driveType }}</td>
<td>S-3900</td> <td id="examExpirationDate{{ $vehicle->id }}">{{ $vehicle->examExpirationDate }}</td>
<td>-</td> <td id="insuranceExpirationDate{{ $vehicle->id }}">{{ $vehicle->insuranceExpirationDate }}</td>
<td>368-81</td> <td><a href="{{ URL::asset('pojazdy/edit/'.$vehicle->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td>
<td>2001</td> </tr>
<td>Honda 11kW</td> @endforeach
<td>23.04.2020r</td> </table>
<td>24.04.2020r</td>
</tr> @endif
</table> @else
Brak autoryzacji
@endif
@stop @stop

View File

@ -0,0 +1,122 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/pojazdy/add"><li>Dodaj<img src="img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="img/left_menu_icon/delete.png"></li>
<li>Zawieś<img src="img/left_menu_icon/suspended.png"></li>
</ul>
@stop
@section('center-area')
@parent
<form method="POST" action="/pojazdy">
{{ csrf_field() }}
<div class="form-group">
<label for="name">Nazwa:</label>
<input type="text" class="form-control" id="name" name="name" value="{{ old('name') }} ">
</div>
<div class="form-group">
<label for="codename">Kryptonim:</label>
<input type="text" class="form-control" id="codename" name="codename" value="{{ old('codename') }}">
</div>
<div class="form-group">
<label for="brand">Marka:</label>
<input type="text" class="form-control" id="brand" name="brand" value="{{ old('brand') }}">
</div>
<div class="form-group">
<label for="registrationNumber">Numer rejestracyjny:</label>
<input type="text" class="form-control" id="registrationNumber" name="registrationNumber" value="{{ old('registrationNumber') }}">
</div>
<div class="form-group">
<label for="productionYear">Rok produkcji:</label>
<input type="text" class="form-control" id="productionYear" name="productionYear" value="{{ old('productionYear') }}">
</div>
<div class="form-group">
<label for="examExpirationDate">Data ważności przeglądu:</label>
<input type="date" class="form-control" id="examExpirationDate" name="examExpirationDate" value="{{ old('examExpirationDate') }}">
</div>
<div class="form-group">
<label for="insuranceExpirationDate">Termin ważności ubezpieczenia OC:</label>
<input type="date" class="form-control" id="insuranceExpirationDate" name="insuranceExpirationDate" value="{{ old('insuranceExpirationDate') }}">
</div>
<div class="form-group">
<label for="driveType">Układ napędowy:</label>
<input type="text" class="form-control" id="driveType" name="driveType" value="{{ old('driveType') }}">
</div>
<div class="form-group">
<label for="chassisType">Typ podwozia:</label>
<input type="text" class="form-control" id="chassisType" name="chassisType" value="{{ old('chassisType') }}">
</div>
<div class="form-group">
<label for="bodyProducer">Producent nadwozia:</label>
<input type="text" class="form-control" id="bodyProducer" name="bodyProducer" value="{{ old('bodyProducer') }}">
</div>
<div class="form-group">
<label for="crewNumber">Ilość osób w załodze:</label>
<input type="text" class="form-control" id="crewNumber" name="crewNumber" value="{{ old('crewNumber') }}">
</div>
<div class="form-group">
<label for="foamAgent">Ilość środka pianotwórczego w litrach:</label>
<input type="text" class="form-control" id="foamAgent" name="foamAgent" value="{{ old('foamAgent') }}">
</div>
<div class="form-group">
<label for="enginePower">Moc silnika w kW:</label>
<input type="text" class="form-control" id="enginePower" name="enginePower" value="{{ old('enginePower') }}">
</div>
<div class="form-group">
<label for="mass">Masa całkowita pojazdu:</label>
<input type="text" class="form-control" id="mass" name="mass" value="{{ old('mass') }}">
</div>
<div class="form-group">
<label for="chassisNumber">Numer podwozia:</label>
<input type="text" class="form-control" id="chassisNumber" name="chassisNumber" value="{{ old('chassisNumber') }}">
</div>
<div class="form-group">
<label for="engineNumber">Numer silnika:</label>
<input type="text" class="form-control" id="engineNumber" name="engineNumber" value="{{ old('engineNumber') }}">
</div>
<div class="form-group">
<label for="fuelType">Rodzaj paliwa:</label>
<input type="text" class="form-control" id="fuelType" name="fuelType" value="{{ old('fuelType') }}">
</div>
<div class="form-group">
<label for="chassisPoductionYear">Rok produkcji podwozia:</label>
<input type="text" class="form-control" id="chassisPoductionYear" name="chassisPoductionYear" value="{{ old('chassisPoductionYear') }}">
</div>
<div class="form-group">
<label for="entryIntoServiceDate">Data wprowadzenia do eksploatacji:</label>
<input type="text" class="form-control" id="entryIntoServiceDate" name="entryIntoServiceDate" value="{{ old('entryIntoServiceDate') }}">
</div>
<div class="form-group">
<label for="fireEnginePumpDescription">Opis autopompy:</label>
<input type="text" class="form-control" id="fireEnginePumpDescription" name="fireEnginePumpDescription" value="{{ old('fireEnginePumpDescription') }}">
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zatwierdź</button>
</div>
@include('inc.formerrors')
</form>
@stop

View File

@ -0,0 +1,124 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/pojazdy/add"><li>Dodaj<img src="img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="img/left_menu_icon/delete.png"></li>
<li>Zawieś<img src="img/left_menu_icon/suspended.png"></li>
</ul>
@stop
@section('center-area')
@parent
<form method="POST" action="/pojazdy/edit">
{{ csrf_field() }}
<input type="hidden" class="form-control" name="vehicleID" value="{{ $vehicle->id }}">
<div class="form-group">
<label for="name">Nazwa:</label>
<input type="text" class="form-control" id="name" name="name" value="{{ $vehicle->name }} ">
</div>
<div class="form-group">
<label for="codename">Kryptonim:</label>
<input type="text" class="form-control" id="codename" name="codename" value="{{ $vehicle->codename }}">
</div>
<div class="form-group">
<label for="brand">Marka:</label>
<input type="text" class="form-control" id="brand" name="brand" value="{{ $vehicle->brand }}">
</div>
<div class="form-group">
<label for="registrationNumber">Numer rejestracyjny:</label>
<input type="text" class="form-control" id="registrationNumber" name="registrationNumber" value="{{ $vehicle->registrationNumber }}">
</div>
<div class="form-group">
<label for="productionYear">Rok produkcji:</label>
<input type="text" class="form-control" id="productionYear" name="productionYear" value="{{ $vehicle->productionYear }}">
</div>
<div class="form-group">
<label for="examExpirationDate">Data ważności przeglądu:</label>
<input type="date" class="form-control" id="examExpirationDate" name="examExpirationDate" value="{{ $vehicle->examExpirationDate }}">
</div>
<div class="form-group">
<label for="insuranceExpirationDate">Termin ważności ubezpieczenia OC:</label>
<input type="date" class="form-control" id="insuranceExpirationDate" name="insuranceExpirationDate" value="{{ $vehicle->insuranceExpirationDate }}">
</div>
<div class="form-group">
<label for="driveType">Układ napędowy:</label>
<input type="text" class="form-control" id="driveType" name="driveType" value="{{ $vehicle->driveType }}">
</div>
<div class="form-group">
<label for="chassisType">Typ podwozia:</label>
<input type="text" class="form-control" id="chassisType" name="chassisType" value="{{ $vehicle->chassisType }}">
</div>
<div class="form-group">
<label for="bodyProducer">Producent nadwozia:</label>
<input type="text" class="form-control" id="bodyProducer" name="bodyProducer" value="{{ $vehicle->bodyProducer }}">
</div>
<div class="form-group">
<label for="crewNumber">Ilość osób w załodze:</label>
<input type="text" class="form-control" id="crewNumber" name="crewNumber" value="{{ $vehicle->crewNumber }}">
</div>
<div class="form-group">
<label for="foamAgent">Ilość środka pianotwórczego w litrach:</label>
<input type="text" class="form-control" id="foamAgent" name="foamAgent" value="{{ $vehicle->foamAgent }}">
</div>
<div class="form-group">
<label for="enginePower">Moc silnika w kW:</label>
<input type="text" class="form-control" id="enginePower" name="enginePower" value="{{ $vehicle->enginePower }}">
</div>
<div class="form-group">
<label for="mass">Masa całkowita pojazdu:</label>
<input type="text" class="form-control" id="mass" name="mass" value="{{ $vehicle->mass }}">
</div>
<div class="form-group">
<label for="chassisNumber">Numer podwozia:</label>
<input type="text" class="form-control" id="chassisNumber" name="chassisNumber" value="{{ $vehicle->chassisNumber }}">
</div>
<div class="form-group">
<label for="engineNumber">Numer silnika:</label>
<input type="text" class="form-control" id="engineNumber" name="engineNumber" value="{{ $vehicle->engineNumber }}">
</div>
<div class="form-group">
<label for="fuelType">Rodzaj paliwa:</label>
<input type="text" class="form-control" id="fuelType" name="fuelType" value="{{ $vehicle->fuelType }}">
</div>
<div class="form-group">
<label for="chassisPoductionYear">Rok produkcji podwozia:</label>
<input type="text" class="form-control" id="chassisPoductionYear" name="chassisPoductionYear" value="{{ $vehicle->chassisPoductionYear }}">
</div>
<div class="form-group">
<label for="entryIntoServiceDate">Data wprowadzenia do eksploatacji:</label>
<input type="text" class="form-control" id="entryIntoServiceDate" name="entryIntoServiceDate" value="{{ $vehicle->entryIntoServiceDate }}">
</div>
<div class="form-group">
<label for="fireEnginePumpDescription">Opis autopompy:</label>
<input type="text" class="form-control" id="fireEnginePumpDescription" name="fireEnginePumpDescription" value="{{ $vehicle->fireEnginePumpDescription }}">
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zatwierdź zmiany</button>
</div>
@include('inc.formerrors')
</form>
@stop

View File

@ -56,6 +56,12 @@ Route::post('/jednostka', 'fireStationController@store');
Route::get('/jednostka/getcounties/{id}','DataController@getCounties'); Route::get('/jednostka/getcounties/{id}','DataController@getCounties');
Route::get('/jednostka/getcommunities/{id}','DataController@getCommunities'); Route::get('/jednostka/getcommunities/{id}','DataController@getCommunities');
Route::get('/pojazdy', 'VehiclesController@create');
Route::get('/pojazdy/add', 'VehiclesController@addForm');
Route::post('/pojazdy', 'VehiclesController@store');
Route::get('/pojazdy/edit/{id}', 'VehiclesController@editForm');
Route::post('/pojazdy/edit', 'VehiclesController@update');
Route::get('register/verify/{confirmationCode}', [ Route::get('register/verify/{confirmationCode}', [
'as' => 'confirmation_path', 'as' => 'confirmation_path',