%PDF- %PDF-
Direktori : /home/silvzytp/crm-ind-code/app/Http/Controllers/Backend/Super/ |
Current File : //home/silvzytp/crm-ind-code/app/Http/Controllers/Backend/Super/DashboardController.php |
<?php namespace App\Http\Controllers\Backend\Super; use App\Models\User; use App\Models\Channel; use App\Models\Colling; use App\Models\Emirate; use App\Models\Campaign; use App\Models\Category; use App\Models\LeadType; use App\Models\Location; use App\Models\ActivityLog; use App\Models\MonthlyData; use Illuminate\Http\Request; use App\Models\MarketingSource; use App\Models\IndividualTarget; use Illuminate\Support\Facades\DB; use App\Http\Controllers\Controller; use App\Models\FreshLead; use Illuminate\Support\Facades\Gate; use Yajra\DataTables\Facades\DataTables; class DashboardController extends Controller { public function dashboard(){ page_title('Dashboard'); return view('backend.pages.dashboard'); } public function coldCallingDashboard(){ $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('Cold Calling Dashboard'); return view('backend.modules.cold-calling-portal.dashboard', $data); } public function filter(Request $request){ if($request->ajax()){ $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 ($agent != '') { $query->where('agent_id',$agent); } if (!empty($status)) { $query->where('status',$status); } if (!empty($sub_status)) { $query->where('sub_status',$sub_status); } if (!empty($potential)) { $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; $data['total_call'] = $query->count(); $data['open_call'] = $query->where('status',1)->count(); $data['in_progress'] = $query->where('sub_status',2)->count(); $data['follow_up'] = $follow_up->where('sub_status',4)->count(); $data['interested'] = $interested->where('sub_status',11)->count(); $data['call_no_reply'] = $call_no_reply->where('sub_status',3)->count(); $data['potential'] = $potential->where('potential',1)->count(); $data['close_call'] = $close_call->where('status',2)->count(); $query->get(); $data = [ 'totalCalling' => $data['total_call'], 'openStatus' => $data['open_call'], 'closedStatus' => $data['close_call'], 'potentialCall' => $data['potential'], 'inProgress' => $data['in_progress'], 'followUp' => $data['follow_up'], 'interested' => $data['interested'], 'callNoReply' => $data['call_no_reply'] ]; return response()->json($data); } } private 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'); } /** * Fresh Lead Portal * * @return \Illuminate\Http\Response */ public function freshLeadDashboard(){ $query = FreshLead::toBase()->where('lead_pool',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(), 'campaigns' => Campaign::toBase()->where('status',1)->get(), 'categories' => Category::toBase()->where('status',1)->get(), 'emirates' => Emirate::toBase()->where('status',1)->get(), 'sources' => MarketingSource::toBase()->where('status',1)->get(), 'channels' => Channel::toBase()->where('status',1)->get(), 'locations' => Location::toBase()->where('status',1)->get(), 'leadTypes' => LeadType::toBase()->where('status',1)->get(), 'totalCalling' => $query->get()->count(), 'openStatus' => $query->where('status_id',1)->count(), 'closedStatus' => $closedStatusQuery->where('status_id',2)->count(), 'potentialCall' => $potentialStatusQuery->where('potential',1)->count(), 'inProgress' => $inProgressQuery->where('sub_status_id', 2)->count(), 'followUp' => $followUpQuery->where('sub_status_id', 4)->count(), 'interested' => $InterestedQuery->where('sub_status_id', 11)->count(), 'callNoReply' => $callNoReplyQuery->where('sub_status_id', 3)->count(), ]; page_title('Fresh Leads Portal'); return view('backend.modules.fresh-lead-portal.dashboard', $data); } protected function fresh_lead_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; $country = $request->country; $hot_link = $request->hot_link; $lead_type = $request->lead_type; $category = $request->category; $campaign = $request->campaign; $channel = $request->channel; $source = $request->source; $location = $request->location; $sub_location = $request->sub_location; $query = DB::table('fresh_leads')->where('lead_pool',0); if ($agent != '') { $query->where('agent_id',$agent); } if ($status != '') { $query->where('status_id',$status); } if ($sub_status != '') { $query->where('sub_status_id',$sub_status); } if ($potential != '') { $query->where('potential',$potential); } if (!empty($start_date) && !empty($end_date)) { $query->whereDate('enquiry_date','>=',$start_date) ->whereDate('enquiry_date','<=',$end_date); } if ($country != '') { $query->where('country',$country); } if ($hot_link != '') { $query->where('hot_link',$hot_link); } if ($lead_type != '') { $query->where('lead_type_id',$lead_type); } if ($category != '') { $query->where('category_id',$category); } if ($campaign != '') { $query->where('campaign_id',$campaign); } if ($channel != '') { $query->where('channel_id',$channel); } if ($source != '') { $query->where('marketing_source_id',$source); } if ($location != '') { $query->where('location_id',$location); } if ($sub_location != '') { $query->where('sub_location_id',$sub_location); } $follow_up = clone $query; $interested = clone $query; $call_no_reply = clone $query; $potential = clone $query; $close_call = clone $query; $data['total_call'] = $query->count(); $data['open_call'] = $query->where('status_id',1)->count(); $data['in_progress'] = $query->where('sub_status_id',2)->count(); $data['follow_up'] = $follow_up->where('sub_status_id',4)->count(); $data['interested'] = $interested->where('sub_status_id',11)->count(); $data['call_no_reply'] = $call_no_reply->where('sub_status_id',3)->count(); $data['potential'] = $potential->where('potential',1)->count(); $data['close_call'] = $close_call->where('status_id',2)->count(); $query->get(); $output = [ 'total_call' => $data['total_call'], 'open_call' => $data['open_call'], 'closed_call' => $data['close_call'], 'potential_call' => $data['potential'], 'in_progress_call' => $data['in_progress'], 'follow_up_call' => $data['follow_up'], 'interested_call' => $data['interested'], 'no_reply_call' => $data['call_no_reply'] ]; return $output; } public function freshLeadDashboardFilter(Request $request){ if ($request->ajax()) { $data = $this->fresh_lead_filter($request); return response()->json($data); } } public function activityLogs(){ $activityLogin = ActivityLog::with('user')->where('type','Login')->orderBy('id', 'desc')->get(); $activityLogout = ActivityLog::with('user')->where('type','Logout')->orderBy('id', 'desc')->get(); $data = [ 'activityLogin' => $activityLogin, 'activityLogout' => $activityLogout, 'breadcrumb' => ['Dashboard'=>route('super.dashboard'),'Activities'=>''] ]; page_title('Activities'); return view('backend.super-admin.dashboard.activities', $data); } }