%PDF- %PDF-
Direktori : /home/silvzytp/calling_code/app/Http/Controllers/Backend/Super/ |
Current File : //home/silvzytp/calling_code/app/Http/Controllers/Backend/Super/DashboardController.php |
<?php namespace App\Http\Controllers\Backend\Super; use App\Models\User; use App\Models\Colling; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Gate; use Yajra\DataTables\Facades\DataTables; class DashboardController extends Controller { public function dashboard(){ $query = Colling::toBase()->where('soft_data',0); $closedStatusQuery = clone $query; $potentialStatusQuery = clone $query; $inProgressQuery = clone $query; $followUpQuery = clone $query; $InterestedQuery = clone $query; $callNoReplyQuery = clone $query; $data = [ 'agents' => User::toBase()->where(['role_id'=>4])->get(), 'statuses' => DB::table('calling_statuses')->where('status',1)->get(), 'totalCalling' => $query->get()->count(), 'openStatus' => $query->where('status',1)->count(), 'closedStatus' => $closedStatusQuery->where('status',2)->count(), 'potentialCall' => $potentialStatusQuery->where('potential',1)->count(), 'inProgress' => $inProgressQuery->where('sub_status', 2)->count(), 'followUp' => $followUpQuery->where('sub_status', 4)->count(), 'interested' => $InterestedQuery->where('sub_status', 11)->count(), 'callNoReply' => $callNoReplyQuery->where('sub_status', 3)->count(), ]; page_title('Dashboard'); return view('backend.super-admin.dashboard.dashboard', $data); } public function filter(Request $request){ $agent = $request->agent; $status = $request->status; $sub_status = $request->sub_status; $potential = $request->potential; $start_date = $request->start_date; $end_date = $request->end_date; $query = DB::table('collings')->where('soft_data',0); if (!empty($agent)) { $query = $query->where('agent_id',$agent); } if (!empty($status)) { $query = $query->where('status',$status); } if (!empty($sub_status)) { $query = $query->where('sub_status',$sub_status); } if (!empty($potential)) { $query = $query->where('potential',$potential); } if (!empty($start_date) && !empty($end_date)) { $query->whereDate('import_date','>=',$start_date) ->whereDate('import_date','<=',$end_date); } $follow_up = clone $query; $interested = clone $query; $call_no_reply = clone $query; $potential = clone $query; $close_call = clone $query; $count['total_call'] = $query->count(); $count['open_call'] = $query->where('status',1)->count(); $count['in_progress'] = $query->where('sub_status',2)->count(); $count['follow_up'] = $follow_up->where('sub_status',4)->count(); $count['interested'] = $interested->where('sub_status',11)->count(); $count['call_no_reply'] = $call_no_reply->where('sub_status',3)->count(); $count['potential'] = $potential->where('potential',1)->count(); $count['close_call'] = $close_call->where('status',2)->count(); $query->get(); $data = [ 'agents' => User::toBase()->where(['role_id'=>4])->get(), 'statuses' => DB::table('calling_statuses')->where('status',1)->get(), 'totalCalling' => $count['total_call'], 'openStatus' => $count['open_call'], 'closedStatus' => $count['close_call'], 'potentialCall' => $count['potential'], 'inProgress' => $count['in_progress'], 'followUp' => $count['follow_up'], 'interested' => $count['interested'], 'callNoReply' => $count['call_no_reply'] ]; return response()->json($data); } protected function dashboard_data(string $param){ if ($param == 'total-call') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where('soft_data',0); } if ($param == 'open-call') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where(['status'=>1,'soft_data'=>0]); } if ($param == 'closed-call') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where(['status'=>2,'soft_data'=>0]); } if ($param == 'potential-call') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where(['potential'=>1,'soft_data'=>0]); } if ($param == 'in-progress-call') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where(['sub_status'=>2,'soft_data'=>0]); } if ($param == 'follow-up-call') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where(['sub_status'=>4,'soft_data'=>0]); } if ($param == 'interested-call') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where(['sub_status'=>11,'soft_data'=>0]); } if ($param == 'called-no-reply') { $getData = Colling::with('agent','callingStatus','callingSubStatus') ->orderBy('id','asc') ->where(['sub_status'=>3,'soft_data'=>0]); } return $getData; } public function dashboardBoxData(Request $request,string $param){ if ($request->ajax()) { $getData = $this->dashboard_data($param); return DataTables::eloquent($getData) ->addIndexColumn() ->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('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','number_1','number_2','action','follow_up1','follow_up2','follow_up3','comment','time_of_call']) ->make(true); } page_title($param); return view('backend.pages.dashboard-data'); } }