%PDF- %PDF-
Direktori : /home/silvzytp/crm-dub-code/app/Http/Controllers/Backend/ |
Current File : //home/silvzytp/crm-dub-code/app/Http/Controllers/Backend/CompareController.php |
<?php namespace App\Http\Controllers\Backend; use DataTables; use App\Models\User; use App\Models\Colling; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; use App\Models\CallingSubStatus; class CompareController extends Controller { public function index(){ // authorized Gate::authorize('app.compare.index'); // page title page_title('Compare'); // breadcrumb $breadcrumb = ['Dashboard'=>route(routeName().'.dashboard'),'Compare'=>'']; return view('backend.pages.compare.index',['breadcrumb'=>$breadcrumb]); } public function getData(Request $request){ if ($request->ajax()) { if (Auth::user()->role->slug == 'manager') { $getData = User::with('role')->where(['role_id'=>4,'manager_id'=>Auth::id()])->latest('id'); }else{ $getData = User::with('role')->where('role_id',4)->latest('id'); } return DataTables::eloquent($getData) ->addIndexColumn() ->filter(function ($query) use ($request){ if (!empty($request->search_text)) { $query->where('role_id',4) ->where('name', 'LIKE',"%{$request->search_text}%") ->orWhere(function($whereQuery) use ($request){ $whereQuery->where('role_id',4) ->where('phone_no','LIKE',"%{$request->search_text}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->where('role_id',4) ->where('email','LIKE',"%{$request->search_text}%"); }); } }) ->addColumn('role', function($user){ $roleName = $user->role ? $user->role->name : ''; return '<span class="badge badge-primary">'.$roleName.'</span>'; }) ->addColumn('bulk_check', function($user){ return ' <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="select-'.$user->id.'" name="checked_data" value="'.$user->id.'"> <label class="custom-control-label" for="select-'.$user->id.'"></label> </div> '; }) ->rawColumns(['bulk_check','role']) ->make(true); } } public function filter(Request $request){ $data = explode(',', $request->agent); if (Auth::user()->role->slug == 'manager') { $compareData = User::with('callings')->where('manager_id',Auth::id())->whereIn('id',$data)->get(); } $compareData = User::with('callings')->whereIn('id',$data)->get(); // page title page_title('Compare Filter'); // breadcrumb $breadcrumb = ['Dashboard'=>route(routeName().'.dashboard'),'Compare'=>route(routeName().'.compare.index'), 'Filter'=>'']; return view('backend.pages.compare.compare',['breadcrumb'=>$breadcrumb,'compareData'=>$compareData]); } public function fileCompareForm(Request $request){ if ($request->ajax()) { $getData = Colling::selectRaw('file_name, COUNT(*) as total_count,id') ->groupBy('file_name'); return DataTables::eloquent($getData) ->addIndexColumn() ->filter(function ($query) use ($request){ if (!empty($request->search_input)) { $query->where('file_name', 'LIKE',"%{$request->search_input}%"); } }) ->addColumn('total_call', function($call){ return $call->total_count; }) ->addColumn('bulk_check', function($call){ return ' <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="select-'.$call->id.'" name="checked_data" value="'.$call->id.'"> <label class="custom-control-label" for="select-'.$call->id.'"></label> </div> '; }) ->rawColumns(['bulk_check']) ->make(true); } if(Auth::user()->role_id == 1 || Auth::user()->role_id == 2){ // page title page_title('File Compare'); // breadcrumb $breadcrumb = ['Dashboard'=>route(routeName().'.dashboard'),'File Compare'=>'']; return view('backend.pages.compare.file-compare-form',['breadcrumb'=>$breadcrumb]); }else{ return back()->with('error','Unauthorized Block!'); } } public function fileCompareFilter(Request $request){ $data = explode(',', $request->compare); $compareData = Colling::whereIn('id',$data)->select('id','file_name','status','potential')->get(); // page title page_title('File Compare'); // breadcrumb $breadcrumb = ['Dashboard'=>route(routeName().'.dashboard'),'File Compare'=>route(routeName().'.file.compare.index'), 'Compare'=>'']; $sub_status = CallingSubStatus::toBase()->where('status','1')->get(); return view('backend.pages.compare.file-compare',['breadcrumb'=>$breadcrumb,'compareData'=>$compareData,'sub_status'=>$sub_status]); } }