2019-11-17 17:08:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\vehicle;
|
|
|
|
use DB;
|
|
|
|
use Carbon\Carbon; // formatowanie daty
|
|
|
|
|
|
|
|
function formatDate($date)
|
|
|
|
{
|
2019-12-06 21:22:15 +01:00
|
|
|
if ($date == null)
|
|
|
|
return $date;
|
|
|
|
else
|
|
|
|
$fdate = Carbon::parse($date);
|
|
|
|
return $fdate;
|
2019-11-17 17:08:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class VehiclesController extends Controller
|
|
|
|
{
|
|
|
|
public function create(){
|
|
|
|
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
|
|
|
$vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID)
|
2020-01-30 17:34:16 +01:00
|
|
|
->whereNull('deleted_at')->paginate(10);
|
2019-11-17 17:08:02 +01:00
|
|
|
return view("vehicles", ["vehicles" => $vehicles]);
|
|
|
|
} else{
|
|
|
|
return view('vehicles');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addForm(){
|
2020-02-01 01:01:26 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik
|
2019-11-17 17:08:02 +01:00
|
|
|
return view('vehiclesAdd');
|
2020-02-01 01:01:26 +01:00
|
|
|
} else return redirect()->to('/pojazdy');
|
2019-11-17 17:08:02 +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-17 17:08:02 +01:00
|
|
|
{
|
2019-11-25 01:10:46 +01:00
|
|
|
|
2020-01-30 17:34:16 +01:00
|
|
|
$vehicle = DB::table('vehicles')->where("id", $id)->first();
|
2019-11-17 17:08:02 +01:00
|
|
|
return view('vehiclesEdit', ["vehicle" => $vehicle]);
|
2020-01-30 17:34:16 +01:00
|
|
|
}
|
2019-11-17 17:08:02 +01:00
|
|
|
else
|
2020-02-01 01:01:26 +01:00
|
|
|
redirect()->to('/pojazdy');
|
2019-11-17 17:08:02 +01:00
|
|
|
}
|
2019-11-25 01:10:46 +01:00
|
|
|
|
2019-11-17 17:08:02 +01:00
|
|
|
public function store(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
2020-01-31 03:13:13 +01:00
|
|
|
'vehicleName' => 'required|max:45',
|
|
|
|
'codename' => 'required|max:45',
|
|
|
|
'brand' => 'max:45',
|
|
|
|
'registrationNumber' => 'max:15',
|
2019-12-06 21:22:15 +01:00
|
|
|
'productionYear' => 'digits:4|nullable',
|
2020-01-31 03:13:13 +01:00
|
|
|
'driveType' => 'max:45',
|
|
|
|
'chassisType' => 'max:45',
|
|
|
|
'bodyProducer' => 'max:45',
|
|
|
|
'crewNumber' => 'numeric|nullable|digits_between:1,2',
|
|
|
|
'foamAgent' => 'numeric|nullable|digits_between:1,10',
|
|
|
|
'enginePower' => 'numeric|nullable|digits_between:1,10',
|
|
|
|
'mass' => 'numeric|nullable|digits_between:1,10',
|
|
|
|
'chassisNumber' => 'max:45',
|
|
|
|
'engineNumber' => 'max:45',
|
|
|
|
'fuelType' => 'max:45',
|
|
|
|
'chassisPoductionYear' => 'digits:4|nullable',
|
|
|
|
'fireEnginePumpDescription' => 'max:250',
|
2019-11-17 17:08:02 +01:00
|
|
|
],
|
|
|
|
[
|
2020-02-01 06:24:15 +01:00
|
|
|
|
2020-01-31 03:13:13 +01:00
|
|
|
'name' => 'nazwa',
|
2019-11-17 17:08:02 +01:00
|
|
|
'required' => ':attribute jest wymagany(e).',
|
2020-01-31 03:13:13 +01:00
|
|
|
'numeric' => ':attribute może zawierać tylko cyfry.',
|
2019-11-17 17:08:02 +01:00
|
|
|
'digits' => ':attribute musi składać się z :digits cyfr.',
|
2020-01-31 03:13:13 +01:00
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
|
|
|
|
'digits_between' => ':attribute jest za duży(a)'
|
2020-02-01 06:24:15 +01:00
|
|
|
|
2019-11-17 17:08:02 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$vehicle = vehicle::create([
|
|
|
|
'fireStationID' => auth()->user()->fireStationID,
|
2020-01-31 03:13:13 +01:00
|
|
|
'name' => $request-> vehicleName,
|
2019-11-25 01:10:46 +01:00
|
|
|
'codename' => $request-> codename,
|
2019-11-17 17:08:02 +01:00
|
|
|
'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,
|
2019-12-28 19:01:42 +01:00
|
|
|
'status' => $request-> status
|
2019-11-17 17:08:02 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
return redirect()->to('/pojazdy');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function update(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
2020-01-31 03:13:13 +01:00
|
|
|
'vehicleName' => 'required|max:45',
|
|
|
|
'codename' => 'required|max:45',
|
|
|
|
'brand' => 'max:45',
|
|
|
|
'registrationNumber' => 'max:15',
|
2019-12-06 21:22:15 +01:00
|
|
|
'productionYear' => 'digits:4|nullable',
|
2020-01-31 03:13:13 +01:00
|
|
|
'driveType' => 'max:45',
|
|
|
|
'chassisType' => 'max:45',
|
|
|
|
'bodyProducer' => 'max:45',
|
|
|
|
'crewNumber' => 'numeric|nullable|digits_between:1,2',
|
|
|
|
'foamAgent' => 'numeric|nullable|digits_between:1,10',
|
|
|
|
'enginePower' => 'numeric|nullable|digits_between:1,10',
|
|
|
|
'mass' => 'numeric|nullable|digits_between:1,10',
|
|
|
|
'chassisNumber' => 'max:45',
|
|
|
|
'engineNumber' => 'max:45',
|
|
|
|
'fuelType' => 'max:45',
|
|
|
|
'chassisPoductionYear' => 'digits:4|nullable',
|
|
|
|
'fireEnginePumpDescription' => 'max:250',
|
2019-11-17 17:08:02 +01:00
|
|
|
],
|
|
|
|
[
|
2020-02-01 06:24:15 +01:00
|
|
|
|
2020-01-31 03:13:13 +01:00
|
|
|
'name' => 'nazwa',
|
2019-11-17 17:08:02 +01:00
|
|
|
'required' => ':attribute jest wymagany(e).',
|
2020-01-31 03:13:13 +01:00
|
|
|
'numeric' => ':attribute może zawierać tylko cyfry.',
|
2019-11-17 17:08:02 +01:00
|
|
|
'digits' => ':attribute musi składać się z :digits cyfr.',
|
2020-01-31 03:13:13 +01:00
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
|
|
|
|
'digits_between' => ':attribute jest za duży(a)'
|
2020-02-01 06:24:15 +01:00
|
|
|
|
2019-11-17 17:08:02 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$vehicle = vehicle::find( $request->vehicleID);
|
2020-01-31 03:13:13 +01:00
|
|
|
$vehicle-> name = $request-> vehicleName;
|
2019-11-25 01:10:46 +01:00
|
|
|
$vehicle-> codename = $request-> codename;
|
2019-11-17 17:08:02 +01:00
|
|
|
$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;
|
2019-12-28 19:01:42 +01:00
|
|
|
$vehicle-> status = $request-> status;
|
2019-11-17 17:08:02 +01:00
|
|
|
$vehicle->save();
|
|
|
|
|
2019-12-06 21:22:15 +01:00
|
|
|
return redirect()->to('/pojazdy');;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
vehicle::where('id',$id)->delete();
|
2020-01-31 16:45:01 +01:00
|
|
|
return response()->json([
|
|
|
|
'success' => 'Record deleted successfully!'
|
|
|
|
]);
|
2019-11-17 17:08:02 +01:00
|
|
|
}
|
2019-12-28 19:01:42 +01:00
|
|
|
|
|
|
|
public function activate()
|
|
|
|
{
|
|
|
|
$request = request();
|
|
|
|
$vehicle = vehicle::find( $request-> vehicleID);
|
|
|
|
$vehicle-> status = 1;
|
|
|
|
$vehicle->save();
|
|
|
|
return redirect()->to('/pojazdy');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deactivate()
|
|
|
|
{
|
|
|
|
$request = request();
|
|
|
|
$vehicle = vehicle::find( $request-> vehicleID);
|
|
|
|
$vehicle-> status = 0;
|
|
|
|
$vehicle->save();
|
|
|
|
return redirect()->to('/pojazdy');
|
|
|
|
}
|
2020-02-01 06:24:15 +01:00
|
|
|
|
|
|
|
public function createAllVehiclesPDF(){
|
|
|
|
if (auth()->user() != null && auth()->user()->fireStationID != null) {
|
|
|
|
$request = request();
|
|
|
|
$test = new documentCreators();
|
|
|
|
$test->createAllVehiclesPDF($request->fireStationID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createSingleVehiclePDF(){
|
|
|
|
if (auth()->user() != null && auth()->user()->fireStationID != null) {
|
|
|
|
$request = request();
|
|
|
|
$test = new documentCreators();
|
|
|
|
$test->createSingleVehiclePDF($request->vehicleID);
|
|
|
|
}
|
|
|
|
}
|
2019-11-17 17:08:02 +01:00
|
|
|
}
|