Viewing file: DashboardController.php (4.95 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller; use App\Models\BillingRequest; use App\Models\Customer; use App\Models\MealPlan; use App\Models\Plan; use App\Models\User; use App\Models\WorkOutPlan;
class DashboardController extends Controller { public function index(){ $cache_in_seconds = config('cache_time');
$user =auth()->user(); $data['weekDates']=getLastNDays(30); $chatInboxes=[]; foreach (getLastNDays(30) as $day){ $chatInboxes[]=isset($inboxes[trim($day, '"')])?$inboxes[trim($day, '"')]:0; } $data['chart_inbox']=[]; $data['chart_sent']=[];
// Check Settings
$availableSettings=[]; $pgs=json_decode(get_settings('payment_gateway')); $app_name=get_settings('app_name'); $recaptcha_site_key=get_settings('recaptcha_site_key'); $app_favicon=get_settings('app_favicon'); $app_logo=get_settings('app_logo'); $contact_info=json_decode(get_settings('contact_info'));
// Mail $mail_name=get_settings('mail_name'); $mail_from=get_settings('mail_from'); $mail_host=get_settings('mail_host'); $mail_port=get_settings('mail_port'); $mail_username=get_settings('mail_username'); $mail_password=get_settings('mail_password'); $mail_encryption=get_settings('mail_encryption');
// Local $local_setting=json_decode(get_settings('local_setting'));
if(!$app_name || !$recaptcha_site_key || !$app_favicon || !$app_logo || !$contact_info || !isset($contact_info->phone_number) || !isset($contact_info->email_address) || !isset($contact_info->address)){ $availableSettings[]=trans("Configure Application Settings"); };
if(!$mail_name || !$mail_from || !$mail_host || !$mail_port || !$mail_username || !$mail_password || !$mail_encryption){ $availableSettings[]=trans("Configure SMTP Settings"); } if(!$local_setting){ $availableSettings[]=trans("Configure Local Settings"); }
$ss=json_decode(get_settings('site_setting')); if(isset($ss) && !$ss->favicon){ $availableSettings[]=trans("Need to upload favicon");}; if(isset($ss) && !$ss->logo){ $availableSettings[]=trans("Need to upload logo");};
$es=json_decode(get_settings('email_setting')); if(isset($es) && !$es->host){ $availableSettings[]=trans("Need to configure email settings");};
$data['available_setting']=$availableSettings;
$data['total_customers'] = Customer::where('status','active')->count(); $data['total_plans'] = Plan::where('status','active')->count(); $data['total_trainers'] = User::where('type','trainer')->count();
$data['total_assigned_customer'] = Customer::where('added_by',$user->id)->count(); $data['total_work_out_plan'] = WorkOutPlan::where('admin_id',$user->id)->count(); $data['total_meal_plan'] = MealPlan::where('admin_id',$user->id)->count();
return view('admin.dashboard',$data); } public function setLocale($type) { $availableLang = get_available_languages();
if (!in_array($type, $availableLang)) abort(400);
session()->put('locale', $type);
return redirect()->back(); }
public function countNotification(){ $adminUsers=Customer::where('added_by', 'admin')->pluck('id'); $planReq=BillingRequest::where('admin_id', auth()->user()->id)->whereIn('customer_id', $adminUsers)->where('status', 'pending')->count(); $tickets=Ticket::where('status', 'pending')->count(); $verifications=0; $topUpReq=TopUpRequest::where('admin_id', auth()->user()->id)->whereIn('customer_id', $adminUsers)->where('status', 'pending')->count(); $domain=Domain::where('status', 'pending')->count(); $numberReq=NumberRequest::where('status', 'pending')->count(); $whatsAppReq=WhatsAppNumberRequest::where('status', 'pending')->count(); $senderId=SenderId::whereIn('status', ['pending','review','review_pending'])->count();
$data=[ 'plan_request'=>$planReq, 'tickets'=>$tickets, 'verifications'=>$verifications, 'topUpReq'=>$topUpReq, 'domain'=>$domain, 'numberReq'=>$numberReq, 'senderId'=>$senderId, 'whatsappReq'=>$whatsAppReq, ]; return response()->json([ $data, 'status'=>'success'], 200); }
public function clearCache(){ $user=auth()->user(); cache()->forget('customers_'.$user); cache()->forget('newMessageCount_'.$user); cache()->forget('newSentCount_'.$user); cache()->forget('totalInbox_'.$user); cache()->forget('totalSent_'.$user); cache()->forget('inboxes_'.$user); cache()->forget('sents_'.$user);
return redirect()->back()->with('success', trans('customer.messages.cache_cleared')); } }
|