%PDF- %PDF-
Direktori : /home/silvzytp/crm-ind-code/app/Http/Controllers/ |
Current File : //home/silvzytp/crm-ind-code/app/Http/Controllers/CallingController.php |
<?php namespace App\Http\Controllers; use Carbon\Carbon; use App\Models\User; use App\Models\Colling; use Illuminate\Http\Request; use App\Models\CallingStatus; use App\Imports\CallingImport; use App\Models\CallingSubStatus; use Illuminate\Support\Facades\DB; use App\Notifications\Notifications; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; use App\Notifications\ReminderNotification; use Maatwebsite\Excel\Facades\Excel; use Yajra\DataTables\Facades\DataTables; class CallingController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // authorized Gate::authorize('app.callings.index'); // page title page_title('Callings'); // breadcrumb $breadcrumb = ['Dashboard'=>route('app.dashboard'),'Callings'=>'']; if (Auth::user()->role->slug == 'manager') { $agents = User::where(['role_id'=>4,'manager_id'=>Auth::id()])->get(); }else{ $agents = User::where('role_id',4)->get(); } // status $statuses = CallingStatus::where('status',1)->get(); if (Auth::user()->role->slug == 'agent') { return view('backend.pages.calling.agent-calling',['breadcrumb'=>$breadcrumb,'statuses'=>$statuses]); } return view('backend.pages.calling.index',['breadcrumb'=>$breadcrumb,'agents'=>$agents,'statuses'=>$statuses]); } public function getData(Request $request){ if ($request->ajax()) { if (Auth::user()->role->slug == 'super-admin' || Auth::user()->role->slug == 'admin') { $getData = Colling::with('agent','callingStatus','callingSubStatus')->orderBy('id','desc') ->where('soft_data',0); }elseif (Auth::user()->role->slug == 'manager'){ $getData = Colling::with('agent','callingStatus','callingSubStatus')->orderBy('id','desc') ->where('soft_data',0) ->whereIn('agent_id',Auth::user()->agents->pluck('id')); } return DataTables::eloquent($getData) ->addIndexColumn() ->filter(function ($query) use ($request){ if(!empty($request->agent)){ $query->where('agent_id',$request->agent); } if(!empty($request->assign_agent_data)){ if($request->assign_agent_data == 2){ $query->whereNull('agent_id'); }else{ $query->where('agent_id','!=',null); } } if(!empty($request->status)){ $query->where('status',$request->status); } if(!empty($request->search_input)){ if (Auth::user()->role_id == 3) { $query->where("number_1","LIKE","%{$request->search_input}%") ->whereIn('agent_id',Auth::user()->agents->pluck('id')) ->orWhere(function($whereQuery) use ($request){ $whereQuery->whereIn('agent_id',Auth::user()->agents->pluck('id')) ->where('phone','LIKE',"%{$request->search_input}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->whereIn('agent_id',Auth::user()->agents->pluck('id')) ->where('email','LIKE',"%{$request->search_input}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->whereIn('agent_id',Auth::user()->agents->pluck('id')) ->where('serial','LIKE',"%{$request->search_input}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->whereIn('number_2',Auth::user()->agents->pluck('id')) ->where('phone','LIKE',"%{$request->search_input}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->whereIn('number_2',Auth::user()->agents->pluck('id')) ->where('number_2','LIKE',"%{$request->search_input}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->whereIn('number_2',Auth::user()->agents->pluck('id')) ->where('name','LIKE',"%{$request->search_input}%"); }); }else{ $query->where("number_1","LIKE","%{$request->search_input}%") ->orWhere('phone','LIKE',"%{$request->search_input}%") ->orWhere('email','LIKE',"%{$request->search_input}%") ->orWhere('name','LIKE',"%{$request->search_input}%") ->orWhere('serial','LIKE',"%{$request->search_input}%") ->orWhere('number_2','LIKE',"%{$request->search_input}%"); } } if(!empty($request->sub_status)){ $query->where('sub_status',$request->sub_status); } if(!empty($request->potential)){ $query->where('potential',$request->potential); } if(!empty($request->start_date) && !empty($request->end_date)){ $query->whereDate('import_date','>=',$request->start_date) ->whereDate('import_date','<=',$request->end_date); } if(!empty($request->call_start_date) && !empty($request->call_end_date)){ $query->whereDate('call_date','>=',$request->call_start_date) ->whereDate('call_date','<=',$request->call_end_date); } if (!empty($request->search_text)) { if (Auth::user()->role_id == 3) { $query->whereIn('agent_id',Auth::user()->agents->pluck('id')) ->where('file_name', $request->search_text); }else{ $query->where('file_name',$request->search_text); } } }) ->addColumn('agent', function($user){ return $user->agent ? $user->agent->name : 'N/A'; }) ->addColumn('importer', function($user){ return $user->importer ? $user->importer->name : 'N/A'; }) ->addColumn('date', function($user){ return date_formats('d-m-Y',$user->import_date); }) ->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" value="'.$user->id.'"> <label class="custom-control-label" for="select-'.$user->id.'"></label> </div> '; }) ->addColumn('time_of_call', function($user){ return '<button type="button" class="btn-style btn-style-view" id="btn-time-data" data-id="'.$user->id.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('number_1', function($user){ return '<a href="tel:'.$user->number_1.'">'.$user->number_1.'</a>'; }) ->addColumn('number_2', function($user){ return '<a href="tel:'.$user->number_2.'">'.$user->number_2.'</a>'; }) ->addColumn('status', function($user){ return $user->callingStatus ? $user->callingStatus->name : 'N/A'; }) ->addColumn('sub_status', function($user){ return $user->callingSubStatus ? $user->callingSubStatus->name : 'N/A'; }) ->addColumn('potential', function($user){ return $user->potential != '' ? POTENTIAL[$user->potential] : 'N/A'; }) ->addColumn('comment', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Comment" data-content="'.$user->comment.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up1', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 1" data-content="'.$user->follow_up1.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up2', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 2" data-content="'.$user->follow_up2.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up3', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 3" data-content="'.$user->follow_up3.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('action', function($user){ $action = ''; if (Gate::allows('app.callings.delete')) { $action .= '<button class="btn-style btn-style-danger ml-1 deletable-btn" data-title="Do you really want to delete this record?" data-id="'.$user->id.'"><i class="fa fa-trash"></i></button>'; } if (Gate::allows('app.callings.edit')) { $action .= '<a href="'.route(routeName().'.callings.edit', $user->id).'" class="btn-style btn-style-edit ml-1" data-id="'.$user->id.'"><i class="fa fa-edit"></i></a>'; } return '<div class="dropdown show text-right">'.$action.'</div>'; }) ->rawColumns(['agent','bulk_check','number_1','number_2','action','follow_up1','follow_up2','follow_up3','comment','time_of_call']) ->make(true); } } public function callingReject(){ // authorized Gate::authorize('app.callings.reject'); // page title page_title('Lead Pool'); $agents = User::where('role_id',4)->get(); // status $statuses = CallingStatus::where('status',1)->get(); // breadcrumb $breadcrumb = ['Dashboard'=>route('app.dashboard'),'Lead Pool'=>'']; return view('backend.pages.calling.reject',['breadcrumb'=>$breadcrumb,'agents'=>$agents,'statuses'=>$statuses]); } public function readPoolGetData(Request $request){ if ($request->ajax()) { $getData = Colling::with('callingStatus','callingSubStatus')->orderBy('id','desc') ->where('soft_data',1); return DataTables::eloquent($getData) ->addIndexColumn() ->filter(function ($query) use ($request){ if(!empty($request->agent)){ $query->where('agent_id',$request->agent); } if(!empty($request->status)){ $query->where('status',$request->status); } if(!empty($request->sub_status)){ $query->where('sub_status',$request->sub_status); } if(!empty($request->potential)){ $query->where('potential',$request->potential); } if(!empty($request->start_date) && !empty($request->end_date)){ $query->whereDate('import_date','>=',$request->start_date) ->whereDate('import_date','<=',$request->end_date); } if (!empty($request->search_text)) { $query->where('soft_data',1) ->where('serial', 'LIKE',"%{$request->search_text}%") ->orWhere(function($whereQuery) use ($request){ $whereQuery->where('soft_data',1) ->where('file_name','LIKE',"%{$request->search_text}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->where('soft_data',1) ->where('email','LIKE',"%{$request->search_text}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->where('soft_data',1) ->where('name','LIKE',"%{$request->search_text}%"); }); } }) ->addColumn('agent', function($user){ return $user->agent ? $user->agent->name : 'N/A'; }) ->addColumn('date', function($user){ return date_formats('d-m-Y',$user->import_date); }) ->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" value="'.$user->id.'"> <label class="custom-control-label" for="select-'.$user->id.'"></label> </div> '; }) ->addColumn('time_of_call', function($user){ return '<button type="button" class="btn-style btn-style-view" id="btn-time-data" data-id="'.$user->id.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('number_1', function($user){ return '<a href="tel:'.$user->number_1.'">'.$user->number_1.'</a>'; }) ->addColumn('number_2', function($user){ return '<a href="tel:'.$user->number_2.'">'.$user->number_2.'</a>'; }) ->addColumn('status', function($user){ return $user->callingStatus ? $user->callingStatus->name : 'N/A'; }) ->addColumn('sub_status', function($user){ return $user->callingSubStatus ? $user->callingSubStatus->name : 'N/A'; }) ->addColumn('potential', function($user){ return $user->potential != '' ? POTENTIAL[$user->potential] : 'N/A'; }) ->addColumn('comment', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Comment" data-content="'.$user->comment.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up1', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 1" data-content="'.$user->follow_up1.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up2', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 2" data-content="'.$user->follow_up2.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up3', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 3" data-content="'.$user->follow_up3.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('action', function($user){ $action = ''; if (Gate::allows('app.callings.delete')) { $action .= '<button class="btn-style btn-style-danger ml-1 deletable-btn" data-title="Do you really want to delete this record?" data-id="'.$user->id.'"><i class="fa fa-trash"></i></button>'; } if (Gate::allows('app.callings.edit')) { $action .= '<a href="'.route(routeName().'.callings.edit', $user->id).'" class="btn-style btn-style-edit ml-1" data-id="'.$user->id.'"><i class="fa fa-edit"></i></a>'; } return '<div class="dropdown show text-right">'.$action.'</div>'; }) ->rawColumns(['agent','bulk_check','number_1','number_2','action','follow_up1','follow_up2','follow_up3','comment','time_of_call']) ->make(true); } } public function readPoolOperation(Request $request){ if ($request->ajax()) { if (!empty($request->bulk_id)) { DB::beginTransaction(); $userId = explode(',', $request->bulk_id); $calling = Colling::whereIn('id', $userId); if ($calling->count() > 0) { try { if ($request->operation_type == 'delete') { $calling->delete(); $output = response_alert('success',ALERT_DELETE); }elseif($request->operation_type == 'assign'){ $calling->update([ 'agent_id'=>$request->manager, 'soft_data'=>0 ]); // notification $data = ['message'=>'Assign new calling data.','date'=>date('Y-m-d H:i:s'),'assign_count'=>$calling->count()]; User::find($request->manager)->notify(new Notifications($data)); $output = response_alert('success',ALERT_SUCCESS); }else{ $output = response_alert('error','Operation somthing wrong!'); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); $output = response_alert('error','Somthing Wrong!'); } }else{ $output = response_alert('error',SERVER_ERROR); } }else{ $output = response_alert('error','Please user selected try'); } return response()->json($output); } } public function import(Request $request){ if ($request->ajax()) { if ($request->hasFile('import_file')) { $import = Excel::import(new CallingImport($request->file_name), $request->file('import_file')); if ($import) { $output = ['status'=>'success','message'=>'Import Successfull.']; } }else{ $output = ['status'=>'error','message'=>'The import field is required.']; } return response()->json($output); } } public function bulkOperation(Request $request){ if ($request->ajax()) { if (!empty($request->bulk_id)) { DB::beginTransaction(); $userId = explode(',', $request->bulk_id); $calling = Colling::whereIn('id', $userId); if ($calling->count() > 0) { try { if ($request->operation_type == 'delete') { $calling->delete(); $output = response_alert('success',ALERT_DELETE); }elseif($request->operation_type == 'assign'){ $calling->update(['agent_id'=>$request->manager]); // notification $data = ['message'=>'Assign new calling data.','date'=>date('Y-m-d H:i:s'),'assign_count'=>$calling->count()]; User::find($request->manager)->notify(new Notifications($data)); $output = response_alert('success',ALERT_SUCCESS); }elseif ($request->operation_type == 'soft') { $calling->update(['soft_data'=>1]); $output = response_alert('success',ALERT_SUCCESS); }elseif($request->operation_type == 'transfer'){ $calling->update(['agent_id'=>$request->manager]); $output = response_alert('success',ALERT_SUCCESS); }else{ $output = response_alert('error','Operation somthing wrong!'); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); $output = response_alert('error',$e->getMessage()); } }else{ $output = response_alert('error',SERVER_ERROR); } }else{ $output = response_alert('error','Please user selected try'); } return response()->json($output); } } public function selectStatus(Request $request){ if ($request->ajax()) { $subStatus = CallingSubStatus::where('status_id',$request->status)->select('id','name')->get(); $output = '<option value="">-- Select Sub Status --</option>'; if (!$subStatus->isEmpty()) { foreach ($subStatus as $status) { $output .= '<option value="'.$status->id.'">'.$status->name.'</option>'; } } return response()->json($output); } } public function statusSelected(Request $request){ if ($request->ajax()) { $calling = Colling::find($request->calling_id); $subStatus = CallingSubStatus::where('status_id',$request->status_id)->select('id','name')->get(); $output = '<option value="">-- Select Sub Status --</option>'; if (!$subStatus->isEmpty()) { foreach ($subStatus as $status) { $selected = $status->id == $calling->sub_status ? 'selected' : ''; $output .= '<option value="'.$status->id.'" '.$selected.'>'.$status->name.'</option>'; } } return response()->json($output); } } public function callingTransfer(){ // authorized Gate::authorize('app.callings.transfer'); // page title page_title('Calling Transfer'); // breadcrumb $breadcrumb = ['Dashboard'=>route('app.dashboard'),'Calling Transfer'=>'']; $agents = User::where('role_id',4)->get(); return view('backend.pages.calling.transfer',['breadcrumb'=>$breadcrumb,'agents'=>$agents]); } public function callingTransferGetData(Request $request){ if ($request->ajax()) { $getData = Colling::with('callingStatus','callingSubStatus') ->where('soft_data',0)->where('agent_id','!=',0); return DataTables::eloquent($getData) ->addIndexColumn() ->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" value="'.$user->id.'"> <label class="custom-control-label" for="select-'.$user->id.'"></label> </div> '; }) ->addColumn('number_1', function($user){ return '<a href="tel:'.$user->number_1.'">'.$user->number_1.'</a>'; }) ->addColumn('number_2', function($user){ return '<a href="tel:'.$user->number_2.'">'.$user->number_2.'</a>'; }) ->addColumn('status', function($user){ return $user->callingStatus ? $user->callingStatus->name : 'N/A'; }) ->addColumn('sub_status', function($user){ return $user->callingSubStatus ? $user->callingSubStatus->name : 'N/A'; }) ->addColumn('action', function($user){ $action = ''; if (Gate::allows('app.callings.show')) { $action .= '<a href="" class="btn-style btn-style-view btn-view ml-1" data-id="'.$user->id.'"><i class="fa fa-eye"></i> </a>'; } if (Gate::allows('app.callings.edit')) { $action .= '<a href="'.route(routeName().'.callings.edit', $user->id).'" class="btn-style btn-style-edit ml-1" data-id="'.$user->id.'"><i class="fa fa-edit"></i> </a>'; } return '<div class="dropdown show text-right">'.$action.'</div>'; }) ->rawColumns(['bulk_check','number_1','number_2','action']) ->make(true); } } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return abort(404); // authorized Gate::authorize('app.callings.create'); // page title page_title('Create Calling'); // breadcrumb $breadcrumb = ['Dashboard'=>route('app.dashboard'),'Callings'=>route(routeName().'.callings.index'),'Create'=>'']; $statuses = CallingStatus::where('status',1)->latest('id')->get(); $subStatuses = CallingSubStatus::where('status',1)->latest('id')->get(); return view('backend.pages.calling.form',['breadcrumb'=>$breadcrumb,'statuses'=>$statuses,'subStatuses'=>$subStatuses]); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'serial' => 'required', 'name' => 'required', 'email' => 'required|email', 'number_1' => 'required', 'status' => 'required|integer', 'sub_status' => 'required|integer' ]); Colling::create([ 'serial' => $request->serial, 'name' => $request->name, 'email' => $request->email, 'number_1' => $request->number_1, 'number_2' => $request->number_2, 'status' => $request->status, 'sub_status' => $request->sub_status, 'comment' => $request->comment, 'time_of_calling' => $request->time_of_calling, 'follow_up1' => $request->follow_up_1, 'follow_up2' => $request->follow_up_2, 'follow_up3' => $request->follow_up_3 ]); return redirect()->route(routeName().'.callings.index')->with('success',ALERT_SUCCESS); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // authorized Gate::authorize('app.callings.edit'); $calling = Colling::findOrFail($id); // page title page_title('Edit Calling'); // breadcrumb $breadcrumb = ['Dashboard'=>route('app.dashboard'),'Callings'=>route(routeName().'.callings.index'),'Edit'=>'']; $statuses = CallingStatus::where('status',1)->latest('id')->get(); $subStatuses = CallingSubStatus::where('status',1)->latest('id')->get(); return view('backend.pages.calling.form',['breadcrumb'=>$breadcrumb, 'calling'=>$calling,'statuses'=>$statuses,'subStatuses'=>$subStatuses]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $request->validate([ 'serial' => 'required', 'name' => 'required', 'email' => 'required|email', 'number_1' => 'required', 'status' => 'required|integer', 'sub_status' => 'required|integer' ]); Colling::find($id)->update([ 'serial' => $request->serial, 'name' => $request->name, 'email' => $request->email, 'number_1' => $request->number_1, 'number_2' => $request->number_2, 'status' => $request->status, 'sub_status' => $request->sub_status, 'comment' => $request->comment, 'time_of_calling' => $request->time_of_calling, 'follow_up1' => $request->follow_up_1, 'follow_up2' => $request->follow_up_2, 'follow_up3' => $request->follow_up_3, 'potential' => $request->potential ]); return redirect()->route(routeName().'.callings.index')->with('success',ALERT_UPDATE); } public function managerImportgetData(Request $request){ if ($request->ajax()) { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->where(['soft_data'=>0,'import_id'=>auth()->user()->id]); return DataTables::eloquent($getData) ->addIndexColumn() ->filter(function ($query) use ($request){ if(!empty($request->agent)){ $query->where('agent_id',$request->agent); } if(!empty($request->assign_agent_data)){ if($request->assign_agent_data == 2){ $query->whereNull('agent_id'); }else{ $query->where('agent_id','!=',null); } } if(!empty($request->status)){ $query->where('status',$request->status); } if(!empty($request->sub_status)){ $query->where('sub_status',$request->sub_status); } if(!empty($request->potential)){ $query->where('potential',$request->potential); } if(!empty($request->start_date) && !empty($request->end_date)){ $query->whereDate('import_date','>=',$request->start_date) ->whereDate('import_date','<=',$request->end_date); } if(!empty($request->call_start_date) && !empty($request->call_end_date)){ $query->whereDate('call_date','>=',$request->call_start_date) ->whereDate('call_date','<=',$request->call_end_date); } if (!empty($request->search_text)) { $query->where('file_name', $request->search_text); } }) ->addColumn('agent', function($user){ return $user->agent ? $user->agent->name : 'N/A'; }) ->addColumn('date', function($user){ return date_formats('d-m-Y',$user->import_date); }) ->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" value="'.$user->id.'"> <label class="custom-control-label" for="select-'.$user->id.'"></label> </div> '; }) ->addColumn('time_of_call', function($user){ return '<button type="button" class="btn-style btn-style-view" id="btn-time-data" data-id="'.$user->id.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('number_1', function($user){ return '<a href="tel:'.$user->number_1.'">'.$user->number_1.'</a>'; }) ->addColumn('number_2', function($user){ return '<a href="tel:'.$user->number_2.'">'.$user->number_2.'</a>'; }) ->addColumn('status', function($user){ return $user->callingStatus ? $user->callingStatus->name : 'N/A'; }) ->addColumn('sub_status', function($user){ return $user->callingSubStatus ? $user->callingSubStatus->name : 'N/A'; }) ->addColumn('potential', function($user){ return $user->potential != '' ? POTENTIAL[$user->potential] : 'N/A'; }) ->addColumn('comment', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Comment" data-content="'.$user->comment.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up1', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 1" data-content="'.$user->follow_up1.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up2', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 2" data-content="'.$user->follow_up2.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up3', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 3" data-content="'.$user->follow_up3.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('action', function($user){ $action = ''; if (Gate::allows('app.callings.delete')) { $action .= '<button class="btn-style btn-style-danger ml-1 deletable-btn" data-title="Do you really want to delete this record?" data-id="'.$user->id.'"><i class="fa fa-trash"></i></button>'; } if (Gate::allows('app.callings.edit')) { $action .= '<a href="'.route(routeName().'.callings.edit', $user->id).'" class="btn-style btn-style-edit ml-1" data-id="'.$user->id.'"><i class="fa fa-edit"></i></a>'; } return '<div class="dropdown show text-right">'.$action.'</div>'; }) ->rawColumns(['agent','bulk_check','number_1','number_2','action','follow_up1','follow_up2','follow_up3','comment','time_of_call']) ->make(true); } // page title page_title('Import Call'); // breadcrumb $breadcrumb = ['Dashboard'=>route('app.dashboard'),'Import Call'=>'']; $agents = User::where(['role_id'=>4,'manager_id'=>Auth::id()])->get(); $statuses = CallingStatus::where('status',1)->get(); return view('backend.pages.calling.import-list',['breadcrumb'=>$breadcrumb,'agents'=>$agents,'statuses'=>$statuses]); } public function agentGetData(Request $request){ if ($request->ajax()) { $getData = Colling::with('agent','callingStatus','callingSubStatus')->orderBy('id','desc') ->where(['agent_id'=>Auth::id(),'soft_data'=>0]); return DataTables::eloquent($getData) ->addIndexColumn() ->filter(function ($query) use ($request){ if(!empty($request->status)){ $query->where('status',$request->status); } if(!empty($request->sub_status)){ $query->where('sub_status',$request->sub_status); } if(!empty($request->potential)){ $query->where('potential',$request->potential); } if(!empty($request->start_date) && !empty($request->end_date)){ $query->whereDate('import_date','>=',$request->start_date) ->whereDate('import_date','<=',$request->end_date); } if (!empty($request->search_text)) { $query->where(['agent_id'=>Auth::id(),'soft_data'=>0]) ->where('serial', 'LIKE',"%{$request->search_text}%") ->orWhere(function($whereQuery) use ($request){ $whereQuery->where(['agent_id'=>Auth::id(),'soft_data'=>0]) ->where('file_name','LIKE',"%{$request->search_text}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->where(['agent_id'=>Auth::id(),'soft_data'=>0]) ->where('email','LIKE',"%{$request->search_text}%"); })->orWhere(function($whereQuery) use ($request){ $whereQuery->where(['agent_id'=>Auth::id(),'soft_data'=>0]) ->where('name','LIKE',"%{$request->search_text}%"); }); } }) ->addColumn('agent', function($user){ return $user->agent ? $user->agent->name : 'N/A'; }) ->addColumn('date', function($user){ return date_formats('d-m-Y',$user->import_date); }) ->addColumn('time_of_call', function($user){ return '<button type="button" class="btn-style btn-style-view" id="btn-time-data" data-id="'.$user->id.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('potential', function($user){ return $user->potential != '' ? POTENTIAL[$user->potential] : 'N/A'; }) ->addColumn('number_1', function($user){ return '<a href="tel:'.$user->number_1.'">'.$user->number_1.'</a>'; }) ->addColumn('number_2', function($user){ return '<a href="tel:'.$user->number_2.'">'.$user->number_2.'</a>'; }) ->addColumn('status', function($user){ return $user->callingStatus ? $user->callingStatus->name : ''; }) ->addColumn('sub_status', function($user){ return $user->callingSubStatus ? $user->callingSubStatus->name : ''; }) ->addColumn('comment', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Comment" data-content="'.$user->comment.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up1', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 1" data-content="'.$user->follow_up1.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up2', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 2" data-content="'.$user->follow_up2.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('follow_up3', function($user){ return '<button type="button" class="btn-style btn-style-view data-view" data-id="'.$user->id.'" data-type="Follow up 3" data-content="'.$user->follow_up3.'" data-serial="'.$user->serial.'"><i class="fas fa-eye"></i></button>'; }) ->addColumn('action', function($user){ $action = ''; if (Gate::allows('app.callings.edit')) { $action .= '<button class="btn-style btn-style-edit btn-edit" data-id="'.$user->id.'"><i class="fa fa-edit"></i></button>'; } return '<div class="dropdown show text-right">'.$action.'</div>'; }) ->rawColumns(['agent','comment','follow_up1','follow_up2','follow_up3','number_1','number_2','action','status','sub_status','time_of_call']) ->make(true); } } public function callingTime(Request $request){ if ($request->ajax()) { $calling = Colling::find($request->data_id); $data = view('backend.modal.calling_time', ['calling'=>$calling])->render(); return response()->json($data); } } public function callingAgentEdit(Request $request){ if ($request->ajax()) { $calling = Colling::find($request->data_id); $statuses = CallingStatus::toBase()->where('status',1)->latest('id')->get(); $subStatuses = CallingSubStatus::toBase()->where('status',1)->latest('id')->get(); if ($calling) { $render = view('backend.modal.calling-render', compact('calling','statuses','subStatuses'))->render(); return response()->json($render); }else{ return response()->json([ 'status'=>'error', 'message'=>'Somthing Wrong!' ]); } } } public function callingAgentUpdate(Request $request){ if ($request->ajax()) { $update = Colling::find($request->calling_id); $update->update([ 'comment' => $request->comment, 'status' => $request->status, 'sub_status' => $request->sub_status, 'follow_up1' => $request->follow_up1, 'follow_up2' => $request->follow_up2, 'follow_up3' => $request->follow_up3, 'potential' => $request->potential ]); if ($request->reminder_date != '') { $reminder_date = date('Y-m-d H:i:s A',strtotime($request->reminder_date)); $update->update([ 'reminder_date'=>$reminder_date ]); } if(!empty($request->status) && !empty($request->sub_status) || !empty($request->status)){ $update->update(['call_date'=>Carbon::now()]); } if (!empty($request->comment)) { $collection = collect($update->comment_time); $collection->push(date('Y-m-d H:i:s')); $update->update(['comment_time'=>$collection]); } if (!empty($request->follow_up1)) { $collection = collect($update->follow_up1_time); $collection->push(date('Y-m-d H:i:s')); $update->update(['follow_up1_time'=>$collection]); } if (!empty($request->follow_up2)) { $collection = collect($update->follow_up2_time); $collection->push(date('Y-m-d H:i:s')); $update->update(['follow_up2_time'=>$collection]); } if (!empty($request->follow_up3)) { $collection = collect($update->follow_up3_time); $collection->push(date('Y-m-d H:i:s')); $update->update(['follow_up3_time'=>$collection]); } if ($update) { $output = ['status'=>'success','message'=>ALERT_SUCCESS]; }else{ $output = ['status'=>'success','message'=>'Somthing Wrong!']; } return response()->json($output); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Request $request) { if ($request->ajax()) { $delete = Colling::find($request->data_id)->delete(); if ($delete) { $output = ['status'=>'success','message'=>ALERT_DELETE]; }else{ $output = ['status'=>'error','message'=>'Somthing Wrong!']; } return response()->json($output); } } }