Initial Commit

This commit is contained in:
dann4624
2022-09-28 09:38:08 +02:00
parent cac476f80f
commit 2d04a269e6
355 changed files with 52166 additions and 25 deletions
@@ -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');
}
}