Initial Commit
This commit is contained in:
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
Reference in New Issue
Block a user