Initial Commit
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\LoanerType;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* checks login credentials
|
||||
* @param Request $request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function authenticate(Request $request)
|
||||
{
|
||||
//validates username and password
|
||||
$credentials = $request->validate([
|
||||
'username' => ['required','string'],
|
||||
'password' => ['required'],
|
||||
|
||||
]);
|
||||
|
||||
//gets the user
|
||||
$user = User::firstWhere('username', "=", $request['username']);
|
||||
//if user is an AD User or not in the database Check login with AD LDAP
|
||||
switch(config('app.login_mode')){
|
||||
case('db'):
|
||||
if (Auth::guard('nadUser')->attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
return $this->getRedirect($user);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (empty($user)) {
|
||||
//check if user exist on the AD and if it does import the data form the ad and make it an AD User
|
||||
if ($adUser = \LdapRecord\Models\ActiveDirectory\User::findBy('samaccountname', $request['username'])) {
|
||||
echo $adUser;
|
||||
$ad_parts = explode(',',$adUser);
|
||||
$name_parts = explode('=',$ad_parts[0]);
|
||||
$name = $name_parts[1];
|
||||
|
||||
$ad_user = new User();
|
||||
$ad_user->guid = $adUser->getConvertedGuid();
|
||||
$ad_user->domain = 'default';
|
||||
$ad_user->name = $name;
|
||||
$ad_user->username = $request['username'];
|
||||
$ad_user->password = Hash::make($request['password']);
|
||||
$ad_user->loanerType()->associate(LoanerType::firstWhere('name', "=", 'adUser')->id);
|
||||
$ad_user->role()->associate(Role::firstWhere('name', "=", 'Elev')->id);
|
||||
$ad_user->save();
|
||||
|
||||
//login with AD
|
||||
if (Auth::guard('adUser')->attempt(['samaccountname' => $credentials['username'], 'password' => $credentials['password']])) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->route('users.show',['user' => $user]);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($user->loanerType->name === 'adUser'){
|
||||
if (Auth::guard('adUser')->attempt(['samaccountname' => $credentials['username'], 'password' => $credentials['password']])) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->route('users.show',['user' => $user]);
|
||||
}
|
||||
}
|
||||
elseif ($user->loanerType->name === 'nadUser') {
|
||||
if (Auth::guard('nadUser')->attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->route('users.show',['user' => $user]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//if the login fails
|
||||
Auth::logout();
|
||||
Session::flush();
|
||||
return back()->withInput($request->input())->withErrors([
|
||||
'username' => 'The provided credentials do not match our records.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the login page
|
||||
* @return Application|Factory|View|RedirectResponse
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
if(Auth::check()){
|
||||
return $this->getRedirect(Auth::user());
|
||||
}
|
||||
|
||||
return view('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* logs a user out of the system
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
Auth::logout();
|
||||
Session::flush();
|
||||
return redirect()->intended('login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cabel;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Helpers\PaginationHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CabelCategory;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CabelCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = CabelCategory::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = CabelCategory::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = CabelCategory::Paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('cabelCategories.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','cabelCategory')
|
||||
->with('data_names','cabelCategories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = CabelCategory::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = CabelCategory::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = CabelCategory::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('cabelCategories.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','cabelCategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('cabelCategories.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$category = new CabelCategory();
|
||||
$category->name = $request->name;
|
||||
$category->save();
|
||||
|
||||
Logger::LogCreated($category->id,get_class($category));
|
||||
|
||||
return redirect()->route('cabelCategories.show',['cabelCategory' => $category]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
|
||||
return view('cabelCategories.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','cabelCategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
|
||||
return view('cabelCategories.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','cabelCategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('cabelCategories.show',['cabelCategory' => $object]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
|
||||
|
||||
return redirect()->route('cabelCategories.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('cabelCategories.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
$object->restore();
|
||||
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('cabelCategories.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cabel;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Helpers\PaginationHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cabel;
|
||||
use App\Models\CabelCategory;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CabelController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
|
||||
array_push($search_types,array("value" => "available", "name" => "available"));
|
||||
array_push($search_types,array("value" => "loans", "name" => "loaned"));
|
||||
array_push($search_types,array("value" => "reservations", "name" => "reserved"));
|
||||
array_push($search_types,array("value" => "total", "name" => "total"));
|
||||
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "available":
|
||||
$all_cabels = Cabel::all();
|
||||
$cabel_collection = collect();
|
||||
foreach($all_cabels as $cabel){
|
||||
$loans = count($cabel->loans);
|
||||
$reservations = count($cabel->reservations);
|
||||
$total = $cabel->total;
|
||||
$available = $total - ($loans + $reservations);
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
if($available >= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("<="):
|
||||
if($available <= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("="):
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$cabels = PaginationHelper::paginate($cabel_collection, $PerPagination);
|
||||
break;
|
||||
case "loans":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('loans', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('loans', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "reservations":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('reservations', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('reservations', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "total":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::where('total','>=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::where('total','<=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$cabels = Cabel::paginate($PerPagination);
|
||||
}
|
||||
return view('cabels.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$cabels)
|
||||
->with('data_name','cabel')
|
||||
->with('data_names','cabels')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
|
||||
array_push($search_types,array("value" => "available", "name" => "available"));
|
||||
array_push($search_types,array("value" => "loans", "name" => "loaned"));
|
||||
array_push($search_types,array("value" => "reservations", "name" => "reserved"));
|
||||
array_push($search_types,array("value" => "total", "name" => "total"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "available":
|
||||
$all_cabels = Cabel::all();
|
||||
$cabel_collection = collect();
|
||||
foreach($all_cabels as $cabel){
|
||||
$loans = count($cabel->loans);
|
||||
$reservations = count($cabel->reservations);
|
||||
$total = $cabel->total;
|
||||
$available = $total - ($loans + $reservations);
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
if($available >= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("<="):
|
||||
if($available <= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("="):
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$cabels = PaginationHelper::paginate($cabel_collection, $PerPagination);
|
||||
break;
|
||||
case "loans":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('loans', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('loans', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "reservations":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('reservations', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('reservations', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "total":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::where('total','>=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::where('total','<=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$cabels = Cabel::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('cabels.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$cabels)
|
||||
->with('data_name','cabel')
|
||||
->with('data_names','cabels')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('cabels.create')
|
||||
->with('categories',CabelCategory::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$cabel = new Cabel();
|
||||
$cabel->cabel_category_id = $request->category_id;
|
||||
$cabel->name = $request->name;
|
||||
$cabel->save();
|
||||
|
||||
Logger::LogCreated($cabel->id,get_class($cabel));
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Cabel $cabel
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
|
||||
return view('cabels.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','cabel')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
|
||||
return view('cabels.edit')
|
||||
->with('categories',CabelCategory::all())
|
||||
->with('data',$object)
|
||||
->with('data_name','cabel')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
if($object->cabel_category_id != $request->category_id){
|
||||
$CabelCategory = CabelCategory::where('id','=',$request->category_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),$logMessage = "Kategori : ".$object->category->name." til ".$CabelCategory->name);
|
||||
$object->cabel_category_id = $request->category_id;
|
||||
|
||||
}
|
||||
if($object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),$logMessage = "Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('cabels.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::withTrashed()->where('id','=',$cabel)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('cabels.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::withTrashed()->where('id','=',$cabel)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('cabels.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the specified amount to the Pool.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_add($cabel,Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_amount_add'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->first();
|
||||
$object->total += $request->amount;
|
||||
$object->save();
|
||||
Logger::LogAmountAdded($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
|
||||
/**Logger::LogAmountAdded($object->id,get_class($object),$request->amount);
|
||||
* Remove the specified amount from the Pool.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_remove($cabel,Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_amount_remove'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->first();
|
||||
$object->total -= $request->amount;
|
||||
$object->save();
|
||||
|
||||
Logger::LogAmountRemoved($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Loan;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Note;
|
||||
use App\Models\NoteType;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class NoteController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "username", "name" => "user"));
|
||||
array_push($search_types,array("value" => "type", "name" => "type"));
|
||||
array_push($search_types,array("value" => "note", "name" => "note"));
|
||||
array_push($search_types,array("value" => "created", "name" => "created_at"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "username":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "note":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$notes = Note::where('note','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$notes = Note::where('note','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "type":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('type',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('type',function ($query) use ($search_term){
|
||||
$query->where('name','like','%'.$search_term.'%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "created":
|
||||
switch($search_compare){
|
||||
default:
|
||||
$parts = explode('.',$search_term);
|
||||
$d = $parts[0];
|
||||
$m = $parts[1];
|
||||
$y = $parts[2];
|
||||
$constructed_date = $y."-".$m."-".$d;
|
||||
$notes = Note::where('created_at','like','%'.$constructed_date.'%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$notes = Note::Paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('notes.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$notes)
|
||||
->with('data_name','note')
|
||||
->with('data_names','notes')
|
||||
->with('without_create','true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$notes = Note::onlyTrashed()->Paginate($PerPagination);
|
||||
|
||||
return view('notes.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$notes)
|
||||
->with('data_name','note')
|
||||
->with('data_names','notes')
|
||||
->with('without_create','true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($note)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
$note_types = NoteType::all();
|
||||
|
||||
return view('notes.edit')
|
||||
->with('data',$note_obj)
|
||||
->with('data_name','note')
|
||||
->with('data_names','notes')
|
||||
->with('types',$note_types)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
|
||||
if($note_obj->note_type_id != $request->type){
|
||||
$type = NoteType::where('id','=',$request->type)->first();
|
||||
Logger::LogEdited($note_obj->id,get_class($note_obj),"Type : ".$note_obj->type->name." til ".$type->name);
|
||||
$note_obj->note_type_id = $request->type;
|
||||
}
|
||||
if($note_obj->note != $request->note) {
|
||||
Logger::LogEdited($note_obj->id,get_class($note_obj),"Note : ".$note_obj->note." til ".$request->note);
|
||||
$note_obj->note = $request->note;
|
||||
}
|
||||
$note_obj->save();
|
||||
|
||||
return redirect()->route('notes.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::where('id','=',$note)->first();
|
||||
Logger::LogDeleted($note_obj->id,get_class($note_obj));
|
||||
$note_obj->delete();
|
||||
|
||||
return redirect()->route('notes.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
Logger::LogForceDeleted($note_obj->id,get_class($note_obj));
|
||||
$note_obj->forceDelete();
|
||||
|
||||
return redirect()->route('notes.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
$note_obj->restore();
|
||||
Logger::LogRestored($note_obj->id,get_class($note_obj));
|
||||
|
||||
return redirect()->route('notes.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Loan;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Illuminate\Auth\Access\Response as Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Response as Fresponse;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
|
||||
class PdfController extends Controller
|
||||
{
|
||||
public function index(Request $request){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'pdf_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "user", "name" => "user"));
|
||||
array_push($search_types,array("value" => "date", "name" => "date"));
|
||||
array_push($search_types,array("value" => "type", "name" => "type"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "user":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$contracts = Contract::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
});
|
||||
})
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$contracts = Contract::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
});
|
||||
})
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "type":
|
||||
switch($search_compare){
|
||||
default:
|
||||
$contracts = Contract::where('type','=',trans($search_term))
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "date":
|
||||
switch($search_compare){
|
||||
case('>='):
|
||||
$parts = explode(' ',$search_term);
|
||||
$date_part = $parts[0];
|
||||
$time_part = $parts[1];
|
||||
$date_parts = explode('.',$date_part);
|
||||
$d = $date_parts[0];
|
||||
$m = $date_parts[1];
|
||||
$y = $date_parts[2];
|
||||
$time_parts = explode(':',$time_part);
|
||||
$h = $time_parts[0];
|
||||
$i = $time_parts[1];
|
||||
$s = $time_parts[2];
|
||||
$date = new DateTime();
|
||||
$timezone = new DateTimeZone('Europe/Copenhagen');
|
||||
$date->setTimezone($timezone);
|
||||
$date->setDate($y,$m,$d);
|
||||
$date->setTime($h,$i,$s);
|
||||
$timestamp = $date->getTimestamp();
|
||||
$contracts = Contract::where('timestamp','>=',$timestamp)
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
case('<='):
|
||||
$parts = explode(' ',$search_term);
|
||||
$date_part = $parts[0];
|
||||
$time_part = $parts[1];
|
||||
$date_parts = explode('.',$date_part);
|
||||
$d = $date_parts[0];
|
||||
$m = $date_parts[1];
|
||||
$y = $date_parts[2];
|
||||
$time_parts = explode(':',$time_part);
|
||||
$h = $time_parts[0];
|
||||
$i = $time_parts[1];
|
||||
$s = $time_parts[2];
|
||||
$date = new DateTime();
|
||||
$timezone = new DateTimeZone('Europe/Copenhagen');
|
||||
$date->setTimezone($timezone);
|
||||
$date->setDate($y,$m,$d);
|
||||
$date->setTime($h,$i,$s);
|
||||
$timestamp = $date->getTimestamp();
|
||||
$contracts = Contract::where('timestamp','<=',$timestamp)
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$parts = explode(' ',$search_term);
|
||||
$date_part = $parts[0];
|
||||
$time_part = $parts[1];
|
||||
$date_parts = explode('.',$date_part);
|
||||
$d = $date_parts[0];
|
||||
$m = $date_parts[1];
|
||||
$y = $date_parts[2];
|
||||
$time_parts = explode(':',$time_part);
|
||||
$h = $time_parts[0];
|
||||
$i = $time_parts[1];
|
||||
$s = $time_parts[2];
|
||||
$date = new DateTime();
|
||||
$timezone = new DateTimeZone('Europe/Copenhagen');
|
||||
$date->setTimezone($timezone);
|
||||
$date->setDate($y,$m,$d);
|
||||
$date->setTime($h,$i,$s);
|
||||
$timestamp = $date->getTimestamp();
|
||||
$contracts = Contract::where('timestamp','=',$timestamp)
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$contracts = Contract::orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('contracts.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data_name','contract')
|
||||
->with('data_names','contracts')
|
||||
->with('data',$contracts)
|
||||
;
|
||||
}
|
||||
|
||||
public function show(Request $request,$user){
|
||||
$user_obj = User::where('username','=',$user)->first();
|
||||
|
||||
if(empty($user_obj)){
|
||||
$user_obj = User::where('name','=',$request->user)->first();
|
||||
}
|
||||
|
||||
if(Auth::user()->id != $user_obj->id){
|
||||
if(!Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'pdf_view'))){
|
||||
return redirect()->intended(route('users.show',Auth::user()));
|
||||
}
|
||||
else{
|
||||
$user = $request->user;
|
||||
$type = $request->type;
|
||||
|
||||
$timestamp = $request->timestamp;
|
||||
$file_name = utf8_encode('app/'.$type."/".$user."_".$timestamp.".pdf");
|
||||
$file_full = storage_path($file_name);
|
||||
return Fresponse::file($file_full);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$user = $request->user;
|
||||
$type = $request->type;
|
||||
|
||||
$timestamp = $request->timestamp;
|
||||
$file_name = utf8_encode('app/'.$type."/".$user."_".$timestamp.".pdf");
|
||||
$file_full = storage_path($file_name);
|
||||
return Fresponse::file($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(Request $request){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'pdf_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$type = $request->type;
|
||||
$user = $request->user;
|
||||
$timestamp = $request->timestamp;
|
||||
|
||||
$file_name = utf8_encode('app/'.$type."/".$user."_".$timestamp.".pdf");
|
||||
$file_full = storage_path($file_name);
|
||||
|
||||
if(file_exists($file_full)){
|
||||
unlink($file_full);
|
||||
}
|
||||
|
||||
$user_obj = User::where('username','=',$user)->first();
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Cabel;
|
||||
use App\Models\Loan;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\Log;
|
||||
use App\Models\LogAction;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OtherController extends Controller
|
||||
{
|
||||
public function logs(Request $request){
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$logs = Log::orderBy('created_at','desc')->Paginate($PerPagination);
|
||||
|
||||
return view('logs')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$logs)
|
||||
->with('data_name','log')
|
||||
->with('data_names','logs')
|
||||
->with('no_deleted',true)
|
||||
;
|
||||
}
|
||||
|
||||
public function statistics(Request $request){
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$products = Product::all();
|
||||
$cabels = Cabel::all();
|
||||
$loans = Loan::where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id')
|
||||
->get()
|
||||
;
|
||||
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
$log_returned = Log::where('log_action_id','=',LogAction::where('name','=','returned')->first()->id)->get();
|
||||
$log_returned_placement = Log::where('log_action_id','=',LogAction::where('name','=','returned')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id','created_at')
|
||||
->orderBy('sum','desc')
|
||||
->get()
|
||||
;
|
||||
$log_lent = Log::where('log_action_id','=',LogAction::where('name','=','lent')->first()->id)->get();
|
||||
$log_lent_placement = Log::where('log_action_id','=',LogAction::where('name','=','lent')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('sum','desc')
|
||||
->get()
|
||||
;
|
||||
$log_reserved = Log::where('log_action_id','=',LogAction::where('name','=','reserved')->first()->id)->get();
|
||||
$log_reserved_placement = Log::where('log_action_id','=',LogAction::where('name','=','reserved')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('sum','desc')
|
||||
->get()
|
||||
;
|
||||
$log_validated = Log::where('log_action_id','=',LogAction::where('name','=','validated')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$log_setups = Log::where('log_action_id','=',LogAction::where('name','=','set up')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$log_pickups = Log::where('log_action_id','=',LogAction::where('name','=','picked up')->first()->id)->get();
|
||||
$log_pickups_placement = Log::where('log_action_id','=',LogAction::where('name','=','picked up')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$log_notes = Log::where('log_action_id','=',LogAction::where('name','=','note')->first()->id)->get();
|
||||
$log_notes_placement = Log::where('log_action_id','=',LogAction::where('name','=','note')->first()->id)
|
||||
->select('*',DB::raw('count(user_id) as amount'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$total_lent = 0;
|
||||
$total_reserved = 0;
|
||||
$total_total = 0;
|
||||
|
||||
$lastday_date = Carbon::now()->subDays(1)->toDateTimeString();
|
||||
$lastday_lent = 0;
|
||||
$lastday_reserved = 0;
|
||||
$lastday_returned = 0;
|
||||
$lastday_notes = 0;
|
||||
|
||||
foreach($products as $product){
|
||||
$total_total += $product->total;
|
||||
}
|
||||
|
||||
foreach($cabels as $cabel){
|
||||
$total_total += $cabel->total;
|
||||
}
|
||||
|
||||
foreach($loans as $loan){
|
||||
$total_lent += $loan->amount;
|
||||
}
|
||||
|
||||
foreach($reservations as $reservation){
|
||||
$total_reserved += $reservation->amount;
|
||||
}
|
||||
|
||||
foreach($log_lent as $loan){
|
||||
if($loan->created_at >= $lastday_date){
|
||||
$lastday_lent += $loan->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_reserved as $loan){
|
||||
if($loan->created_at >= $lastday_date){
|
||||
$lastday_reserved += $loan->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_returned as $return){
|
||||
if($return->created_at >= $lastday_date){
|
||||
$lastday_returned += $return->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_pickups as $pickup){
|
||||
if($pickup->created_at >= $lastday_date){
|
||||
$lastday_returned += $pickup->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_notes as $note){
|
||||
if($note->created_at >= $lastday_date){
|
||||
$lastday_notes += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return view('statistics')
|
||||
->with('search_types',$search_types)
|
||||
->with('data_name','statistic')
|
||||
->with('data_names','statistics')
|
||||
->with('lastday_lent',$lastday_lent)
|
||||
->with('lastday_reserved',$lastday_reserved)
|
||||
->with('lastday_returned',$lastday_returned)
|
||||
->with('lastday_notes',$lastday_notes)
|
||||
->with('total_lent',$total_lent)
|
||||
->with('total_reserved',$total_reserved)
|
||||
->with('total_total',$total_total)
|
||||
->with('validated',$log_validated)
|
||||
->with('lent',$log_lent_placement)
|
||||
->with('reserved',$log_reserved_placement)
|
||||
->with('setups',$log_setups)
|
||||
->with('pickups',$log_pickups_placement)
|
||||
->with('returned',$log_returned_placement)
|
||||
->with('notes',$log_notes_placement)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductCategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BrandController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$brands = Brand::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$brands = Brand::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$brands = Brand::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('brands.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$brands)
|
||||
->with('data_name','brand')
|
||||
->with('data_names','brands')
|
||||
;
|
||||
}
|
||||
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$brands = Brand::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$brands = Brand::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$brands = Brand::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('brands.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$brands)
|
||||
->with('data_name','brand')
|
||||
->with('data_names','brands')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('brands.create')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$brand = new Brand();
|
||||
$brand->name = $request->name;
|
||||
$brand->save();
|
||||
Logger::LogCreated($brand->id,get_class($brand));
|
||||
|
||||
return redirect()->route('brands.show',['brand' => $brand]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
return view('brands.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','brand')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
|
||||
return view('brands.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','brand')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Brand $brand
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('brands.show',['brand' => $brand]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('brands.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Brand $brand
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('brands.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently emove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Brand $brand
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('brands.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CabelCategory;
|
||||
use App\Models\Permission;
|
||||
use App\Models\ProductCategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductCategory::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductCategory::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductCategory::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('categories.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','category')
|
||||
->with('data_names','categories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? '10';
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductCategory::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductCategory::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductCategory::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('categories.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','category')
|
||||
->with('data_names','categories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('categories.create')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$category = new ProductCategory();
|
||||
$category->name = $request->name;
|
||||
$category->save();
|
||||
Logger::LogCreated($category->id,get_class($category));
|
||||
|
||||
return redirect()->route('categories.show',['category' => $category]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductCategory $category
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
|
||||
return view('categories.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','category')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductCategory $category
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
|
||||
return view('categories.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','category')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\ProductCategory $category
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('categories.show',['category' => $category]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('categories.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('categories.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('categories.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,506 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Helpers\PaginationHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\ProductSubcategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
if(config('app.barcode_mode') == 'static'){
|
||||
array_push($search_types,array("value" => "barcode", "name" => "barcode"));
|
||||
}
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
array_push($search_types,array("value" => "subcategory", "name" => "subcategory"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
array_push($search_types,array("value" => "model", "name" => "model"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "description", "name" => "description"));
|
||||
|
||||
array_push($search_types,array("value" => "available", "name" => "available"));
|
||||
array_push($search_types,array("value" => "loans", "name" => "loaned"));
|
||||
array_push($search_types,array("value" => "reservations", "name" => "reserved"));
|
||||
array_push($search_types,array("value" => "total", "name" => "total"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "subcategory":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('subcategory',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('subcategory',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "brand":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "model":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('model',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('model',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "description":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where('description','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where('description','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "available":
|
||||
$all_products = Product::all();
|
||||
$product_collection = collect();
|
||||
foreach($all_products as $product){
|
||||
$loans = count($product->loans);
|
||||
$reservations = count($product->reservations);
|
||||
$total = $product->total;
|
||||
$available = $total - ($loans + $reservations);
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
if($available >= $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
case("<="):
|
||||
if($available <= $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
case("="):
|
||||
if($available == $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($available == $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$products = PaginationHelper::paginate($product_collection, $PerPagination);
|
||||
break;
|
||||
case "loans":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$products = Product::has('loans', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$products = Product::has('loans', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$products = Product::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "reservations":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$products = Product::has('reservations', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$products = Product::has('reservations', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$products = Product::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "total":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$products = Product::where('total','>=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$products = Product::where('total','<=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$products = Product::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$products = Product::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('products.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$products)
|
||||
->with('data_name','product')
|
||||
->with('data_names','products')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
if(config('app.barcode_mode') == 'static'){
|
||||
array_push($search_types,array("value" => "barcode", "name" => "barcode"));
|
||||
}
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
array_push($search_types,array("value" => "subcategory", "name" => "subcategory"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
array_push($search_types,array("value" => "model", "name" => "model"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "description", "name" => "description"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$products = Product::onlyTrashed()->Paginate($PerPagination);
|
||||
|
||||
return view('products.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$products)
|
||||
->with('data_name','product')
|
||||
->with('data_names','products')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('products.create')
|
||||
->with('categories',ProductCategory::all())
|
||||
->with('subcategories',ProductSubcategory::all())
|
||||
->with('brands',Brand::has('models')->get())
|
||||
->with('models',ProductModel::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$product = new Product();
|
||||
if(isset($request->barcode)){
|
||||
$product->barcode = $request->barcode;
|
||||
}
|
||||
$product->product_category_id = $request->category_id;
|
||||
$product->product_subcategory_id = $request->subcategory_id;
|
||||
$product->brand_id = $request->brand_id;
|
||||
$product->product_model_id = $request->model_id;
|
||||
$product->name = $request->name;
|
||||
$product->description = $request->description;
|
||||
$product->save();
|
||||
|
||||
Logger::LogCreated($product->id,get_class($product));
|
||||
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
return view('products.show')
|
||||
->with('data',$object)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
|
||||
return view('products.edit')
|
||||
->with('categories',ProductCategory::withTrashed()->get())
|
||||
->with('subcategories',ProductSubcategory::withTrashed()->get())
|
||||
->with('brands',Brand::withTrashed()->has('models')->get())
|
||||
->with('models',ProductModel::withTrashed()->get())
|
||||
->with('data',$object)
|
||||
->with('data_name','product')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
|
||||
if(isset($request->barcode)){
|
||||
if($object->barcode != $request->barcode){
|
||||
Logger::LogEdited($object->id,get_class($object),"Stregkode : ".$object->barcode." til ".$request->barcode);
|
||||
$object->barcode = $request->barcode;
|
||||
}
|
||||
}
|
||||
if($object->product_category_id != $request->category_id) {
|
||||
$category = ProductCategory::where('id','=', $request->category_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Kategori : ".$object->category->name." til ".$category->name);
|
||||
$object->product_category_id = $request->category_id;
|
||||
}
|
||||
if($object->product_subcategory_id != $request->subcategory_id) {
|
||||
$subcategory = ProductSubcategory::where('id','=', $request->subcategory_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Underkategori : ".$object->subcategory->name." til ".$subcategory->name);
|
||||
$object->product_subcategory_id = $request->subcategory_id;
|
||||
}
|
||||
if($object->brand_id != $request->brand_id) {
|
||||
$brand = Brand::where('id','=', $request->brand_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Fabrikant : ".$object->brand_id->name." til ".$brand->name);
|
||||
$object->brand_id = $request->brand_id;
|
||||
}
|
||||
if($object->product_model_id != $request->model_id) {
|
||||
$model = ProductModel::where('id','=', $request->model_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Model : ".$object->model->name." til ".$model->name);
|
||||
$object->product_model_id = $request->model_id;
|
||||
}
|
||||
if($object->name != $request->name) {
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if($object->description != $request->description) {
|
||||
Logger::LogEdited($object->id,get_class($object),"Beskrivels : ".$object->description." til ".$request->description);
|
||||
$object->description = $request->description;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
$object->restore();
|
||||
|
||||
return redirect()->route('products.deleted');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function forceDelete($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('products.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the specified amount to the Pool.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_add($product,Request $request)
|
||||
{
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
$object->total += $request->amount;
|
||||
$object->save();
|
||||
Logger::LogAmountAdded($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('products.show',['product' => $product]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified amount from the Pool.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_remove(Product $product,Request $request)
|
||||
{
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
$object->total -= $request->amount;
|
||||
$object->save();
|
||||
Logger::LogAmountRemoved($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('products.show',['product' => $product]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Permission;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductModel;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductModelController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "brand":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$models = ProductModel::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('models.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$models)
|
||||
->with('data_name','model')
|
||||
->with('data_names','models')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "brand":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$models = ProductModel::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('models.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$models)
|
||||
->with('data_name','model')
|
||||
->with('data_names','models')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('models.create')
|
||||
->with('brands',Brand::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$model = new ProductModel();
|
||||
$model->name = $request->name;
|
||||
$model->brand_id = $request->brand_id;
|
||||
$model->save();
|
||||
Logger::LogCreated($model->id,get_class($model));
|
||||
|
||||
return redirect()->route('models.show',['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
|
||||
return view('models.show')
|
||||
->with('data',$object)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
|
||||
return view('models.edit')
|
||||
->with('data',$object)
|
||||
->with('brands',Brand::withTrashed()->get())
|
||||
->with('data_name','model')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if( $object->brand_id != $request->brand_id){
|
||||
$brand = Brand::withTrashed()->where('id','=',$request->brand_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Fabrikant : ".$object->brand->name." til ".$brand->name);
|
||||
$object->brand_id = $request->brand_id;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('models.show',['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('models.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('models.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('models.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Permission;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductSubcategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductSubcategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductSubcategory::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('subcategories.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','subcategory')
|
||||
->with('data_names','subcategories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductSubcategory::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('subcategories.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','subcategory')
|
||||
->with('data_names','subcategories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('subcategories.create')
|
||||
->with('categories',ProductCategory::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$subcategory = new ProductSubcategory();
|
||||
$subcategory->name = $request->name;
|
||||
$subcategory->product_category_id = $request->category_id;
|
||||
$subcategory->save();
|
||||
Logger::LogCreated($subcategory->id,get_class($subcategory));
|
||||
|
||||
return redirect()->route('subcategories.show',['subcategory' => $subcategory]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductSubcategory $subcategory
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
return view('subcategories.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','subcategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductSubcategory $subcategory
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
|
||||
$data_type = "subcategory";
|
||||
|
||||
return view('subcategories.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name',$data_type)
|
||||
->with('categories',ProductCategory::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\ProductSubcategory $subcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if( $object->product_category_id != $request->category_id){
|
||||
$category = ProductCategory::withTrashed()->where('id','=',$request->category_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Kategori : ".$object->category->name." til ".$category->name);
|
||||
$object->product_category_id = $request->category_id;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('subcategories.show',['subcategory' => $subcategory]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('subcategories.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete_force($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
|
||||
return redirect()->route('subcategories.deleted');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function restore($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('subcategories.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Rooms;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Building;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BuildingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
$buildings = Building::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$buildings = Building::orderBy('name', 'asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('buildings.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$buildings)
|
||||
->with('data_name','building')
|
||||
->with('data_names','buildings')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p');
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
$buildings = Building::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$buildings = Building::onlyTrashed()->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('buildings.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$buildings)
|
||||
->with('data_name','building')
|
||||
->with('data_names','buildings')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('buildings.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$building = new Building();
|
||||
$building->name = $request->name;
|
||||
$building->save();
|
||||
Logger::LogCreated($building->id,get_class($building));
|
||||
|
||||
return redirect()->route('buildings.show',['building' => $building]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function show($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
|
||||
return view('buildings.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','building')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function edit($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
return view('buildings.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','building')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, $building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('buildings.show',['building' => $building]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('buildings.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('buildings.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('buildings.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Rooms;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Building;
|
||||
use App\Models\Loan;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoomController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "building":
|
||||
$rooms = Room::where(function ($query) use ($search_term){
|
||||
$query->whereHas('building',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
case "name":
|
||||
$rooms = Room::where('rooms.name','like','%' . $search_term . '%')->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$rooms = Room::join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('rooms.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$rooms)
|
||||
->with('data_name','room')
|
||||
->with('data_names','rooms')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? '10';
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "building":
|
||||
$rooms = Room::where(function ($query) use ($search_term){
|
||||
$query->whereHas('building',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
break;
|
||||
case "room":
|
||||
$rooms = Room::where('rooms.name','like','%' . $search_term . '%')->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$rooms = Room::onlyTrashed()->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->onlyTrashed()->Paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('rooms.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$rooms)
|
||||
->with('data_name','room')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('rooms.create')
|
||||
->with('buildings',Building::all()->sortBy(['name','asc']))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$room = new Room();
|
||||
$room->building_id = $request->building_id;
|
||||
$room->name = $request->name;
|
||||
$room->save();
|
||||
Logger::LogCreated($room->id,get_class($room));
|
||||
|
||||
return redirect()->route('rooms.show',['room' => $room]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Room $room
|
||||
*/
|
||||
public function show($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->where('room_id','=',$object->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id','loan_type_id','room_id')
|
||||
->orderBy('loan_type_id')
|
||||
->orderBy('user_id')
|
||||
->orderBy('date_start')
|
||||
->orderBy('date_end')
|
||||
->orderBy('loanable_type')
|
||||
->orderBy('loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
return view('rooms.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','room')
|
||||
->with('reservations',$reservations)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
return view('rooms.edit')
|
||||
->with('data',$object)
|
||||
->with('buildings',Building::all()->sortBy([['name','asc']]))
|
||||
->with('data_name','room')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
$object->building_id = $request->building_id;
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if( $object->building_id != $request->building_id){
|
||||
$building = Building::withTrashed()->where('id','=',$request->building_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->building->name." til ".$building->name);
|
||||
$object->building_id = $request->building_id;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('rooms.show',['room' => $room]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('rooms.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('rooms.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('rooms.deleted');
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,446 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Helpers\ActionLogger;
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cabelcategory;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Loan;
|
||||
use App\Models\LoanerType;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\Note;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "username", "name" => "username"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name_full"));
|
||||
array_push($search_types,array("value" => "role", "name" => "role"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "username":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "role":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$users = User::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('users.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$users)
|
||||
->with('data_name','user')
|
||||
->with('data_names','users')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "username", "name" => "username"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "role", "name" => "role"));
|
||||
|
||||
$PerPagination = $request->input('p');
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "username":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "role":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('username', 'like', '%'.$search_term.'%')
|
||||
->orWhere('name', 'like', '%'.$search_term.'%')
|
||||
->orWhereHas('role', function ($query) use ($search_term){
|
||||
$query->where('name', 'like', '%'.$search_term.'%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$users = User::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('users.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$users)
|
||||
->with('data_name','user')
|
||||
->with('data_names','users')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_ceate'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$exclude = array();
|
||||
if(Auth::user()->role->name != "Administrator"){
|
||||
array_push($exclude,Role::firstWhere("name", "=", "Administrator")->id);
|
||||
}
|
||||
|
||||
return view('users.create')
|
||||
->with('loanerTypes', LoanerType::all())
|
||||
->with('roles', Role::all()->except($exclude))
|
||||
->with('password_input_repeat','true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$nadUser = LoanerType::where('name','=','nadUser')->first();
|
||||
$user = new User();
|
||||
$user->name = $request->name;
|
||||
$user->username = $request->username;
|
||||
$user->password = Hash::make($request->password);
|
||||
$user->loaner_type_id = $nadUser->id;
|
||||
$user->role_id = $request->role_id;
|
||||
$user->save();
|
||||
Logger::LogCreated($user->id,get_class($user));
|
||||
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($user)
|
||||
{
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
if(Auth::user()->id != $object->id){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
$loans = Loan::where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->where('user_id','=',$object->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id','date_start','date_end')
|
||||
->orderBy('date_end')
|
||||
->orderBy('date_start')
|
||||
->orderBy('loanable_type')
|
||||
->orderBy('loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->where('user_id','=',$object->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id','loan_type_id','room_id')
|
||||
->orderBy('loan_type_id')
|
||||
->orderBy('room_id')
|
||||
->orderBy('date_start')
|
||||
->orderBy('date_end')
|
||||
->orderBy('loanable_type')
|
||||
->orderBy('loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
$notes = Note::where('user_id','=',$object->id)
|
||||
->get()
|
||||
;
|
||||
|
||||
$contracts = Contract::where('user_id','=',$object->id)
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->get()
|
||||
;
|
||||
|
||||
return view('users.show')
|
||||
->with('data',$object)
|
||||
->with('loans',$loans)
|
||||
->with('reservations',$reservations)
|
||||
->with('contracts',$contracts)
|
||||
->with('notes',$notes)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($user)
|
||||
{
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
if(Auth::user()->id != $object->id){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
$exclude = array();
|
||||
if(Auth::user()->role->name != "Administrator"){
|
||||
array_push($exclude,Role::where("name","=","Administrator")->first()->id);
|
||||
}
|
||||
|
||||
return view('users.edit')
|
||||
->with('data', $object)
|
||||
->with('loanerTypes', LoanerType::all())
|
||||
->with('users', User::all())
|
||||
->with('roles', Role::all()->except($exclude))
|
||||
->with('password_input_repeat','true')
|
||||
->with('data_name', 'user')
|
||||
->with('data_names', 'users')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $user)
|
||||
{
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
if(Auth::user()->id != $object->id){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
return redirect()->route('roles.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($user)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($user)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
$laptop_files = Storage::files('laptops');
|
||||
foreach($laptop_files as $file){
|
||||
$no_dir = str_replace("laptops/", "",$file);
|
||||
$parts = explode('_',$no_dir);
|
||||
$file_name = 'app\\'.$file;
|
||||
$file_full = storage_path($file_name);
|
||||
if($parts[0] == $object->username){
|
||||
unlink($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
$reservation_files = Storage::files('reservation');
|
||||
foreach($reservation_files as $file){
|
||||
$no_dir = str_replace("reservation/", "",$file);
|
||||
$parts = explode('_',$no_dir);
|
||||
$file_name = 'app\\'.$file;
|
||||
$file_full = storage_path($file_name);
|
||||
if($parts[0] == $object->username){
|
||||
unlink($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
$contract_files = Storage::files('contracts');
|
||||
foreach($contract_files as $file){
|
||||
$no_dir = str_replace("contracts/", "",$file);
|
||||
$parts = explode('_',$no_dir);
|
||||
$file_name = 'app\\'.$file;
|
||||
$file_full = storage_path($file_name);
|
||||
if($parts[0] == $object->username){
|
||||
unlink($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($user)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user