/home/kueuepay/public_html/app/Http/Controllers/Admin/DashboardController.php
<?php
namespace App\Http\Controllers\Admin;
use Exception;
use App\Models\User;
use App\Models\Transaction;
use Illuminate\Http\Request;
use App\Models\SupportTicket;
use App\Http\Helpers\Response;
use App\Constants\PaymentGatewayConst;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Constants\SupportTicketConst;
use App\Models\Admin\PaymentGateway;
class DashboardController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$page_title = "Dashboard";
//user data
$total_users = (User::toBase()->count() == 0) ? 1 : User::toBase()->count();
$unverified_user = User::toBase()->where('email_verified',0)->count();
$active_user = User::toBase()->where('status',true)->count();
$banned_user = User::toBase()->where('status',false)->count();
$user_percent = (($active_user * 100 ) / $total_users);
if ($user_percent > 100) {
$user_percent = 100;
}
//Add Money
$total_add_money = (Transaction::where('type',PaymentGatewayConst::TYPEADDMONEY)->toBase()->count() == 0) ? 1 : Transaction::where('type',PaymentGatewayConst::TYPEADDMONEY)->toBase()->count();
$success_add_money = Transaction::where('type',PaymentGatewayConst::TYPEADDMONEY)->where('status',PaymentGatewayConst::STATUSSUCCESS)->toBase()->count();
$pending_add_money = Transaction::where('type',PaymentGatewayConst::TYPEADDMONEY)->where('status',PaymentGatewayConst::STATUSPENDING)->toBase()->count();
$add_money_percent = (($success_add_money * 100 ) / $total_add_money);
if ($add_money_percent > 100) {
$add_money_percent = 100;
}
//transafer money
$total_transfer_money = (Transaction::where('type',PaymentGatewayConst::TYPETRANSFERMONEY)->toBase()->count() == 0) ? 1 : Transaction::where('type',PaymentGatewayConst::TYPETRANSFERMONEY)->toBase()->count();
$success_transfer_money = Transaction::where('type',PaymentGatewayConst::TYPETRANSFERMONEY)->where('status',PaymentGatewayConst::STATUSSUCCESS)->toBase()->count();
$pending_transfer_money = Transaction::where('type',PaymentGatewayConst::TYPETRANSFERMONEY)->where('status',PaymentGatewayConst::STATUSPENDING)->toBase()->count();
$transfer_money_percent = (($success_transfer_money * 100 ) / $total_transfer_money);
if ($transfer_money_percent > 100) {
$transfer_money_percent = 100;
}
//payment
$total_card_payments = (Transaction::where('type',PaymentGatewayConst::CARD_PAYMENT)->toBase()->count() == 0) ? 1 : Transaction::where('type',PaymentGatewayConst::CARD_PAYMENT)->toBase()->count();
$success_card_payments = Transaction::where('type',PaymentGatewayConst::CARD_PAYMENT)->where('status',PaymentGatewayConst::STATUSSUCCESS)->toBase()->count();
$pending_card_payments = Transaction::where('type',PaymentGatewayConst::CARD_PAYMENT)->where('status',PaymentGatewayConst::STATUSPENDING)->toBase()->count();
$card_payments_percent = (($success_card_payments * 100 ) / $total_card_payments);
if ($card_payments_percent > 100) {
$card_payments_percent = 100;
}
//payment
$total_payment_gateways = (PaymentGateway::where('status',true)->toBase()->count() == 0) ? 1 : PaymentGateway::where('status',true)->toBase()->count();
$automatic_gateways = PaymentGateway::where('type',PaymentGatewayConst::AUTOMATIC)->where('status',true)->toBase()->count();
$manual_gateways = PaymentGateway::where('type',PaymentGatewayConst::MANUAL)->where('status',true)->toBase()->count();
$payment_gateways_percent = (($automatic_gateways * 100 ) / $total_payment_gateways);
if ($payment_gateways_percent > 100) {
$payment_gateways_percent = 100;
}
$start = strtotime(date('Y-m-01'));
$end = strtotime(date('Y-m-31'));
$pending_data = [];
$complete_data = [];
$month_day = [];
while ($start <= $end) {
$start_date = date('Y-m-d', $start);
$pending = Transaction::where('status', PaymentGatewayConst::STATUSPENDING)->whereDate('created_at',$start_date)->count();
$complete = Transaction::whereDate('created_at',$start_date)
->where('status', PaymentGatewayConst::STATUSSUCCESS)
->count();
$pending_data[] = $pending;
$complete_data[] = $complete;
$month_day[] = date('Y-m-d', $start);
$start = strtotime('+1 day',$start);
}
// Chart one
$chart_one_data = [
'pending_data' => $pending_data,
'complete_data' => $complete_data,
];
//support ticket
$total_ticket = (SupportTicket::toBase()->count() == 0) ? 1 : SupportTicket::toBase()->count();
$active_ticket = SupportTicket::toBase()->where('status',SupportTicketConst::ACTIVE)->count();
$pending_ticket = SupportTicket::toBase()->where('status',SupportTicketConst::PENDING)->count();
if($pending_ticket == 0 && $active_ticket != 0){
$percent_ticket = 100;
}elseif($pending_ticket == 0 && $active_ticket == 0){
$percent_ticket = 0;
}else{
$percent_ticket = ($active_ticket / ($active_ticket + $pending_ticket)) * 100;
}
$user_chart = [$active_user, $banned_user,$unverified_user,$total_users];
$data = [
'total_users' => $total_users,
'unverified_user' => $unverified_user,
'active_user' => $active_user,
'user_percent' => $user_percent,
'total_add_money' => $total_add_money,
'success_add_money' => $success_add_money,
'pending_add_money' => $pending_add_money,
'add_money_percent' => $add_money_percent,
'total_transfer_money' => $total_transfer_money,
'success_transfer_money' => $success_transfer_money,
'pending_transfer_money' => $pending_transfer_money,
'transfer_money_percent' => $transfer_money_percent,
'total_card_payments' => $total_card_payments,
'success_card_payments' => $success_card_payments,
'pending_card_payments' => $pending_card_payments,
'card_payments_percent' => $card_payments_percent,
'total_payment_gateways' => $total_payment_gateways,
'automatic_gateways' => $automatic_gateways,
'manual_gateways' => $manual_gateways,
'payment_gateways_percent' => $payment_gateways_percent,
'total_ticket' => $total_ticket,
'active_ticket' => $active_ticket,
'pending_ticket' => $pending_ticket,
'percent_ticket' => $percent_ticket,
'user_chart_data' => $user_chart,
'chart_one_data' => $chart_one_data,
'month_day' => $month_day,
'total_user_count' => User::all()->count(),
'total_add_money_count' => Transaction::where('type',PaymentGatewayConst::TYPEADDMONEY)->count(),
'total_transfer_money_count' => Transaction::where('type',PaymentGatewayConst::TYPETRANSFERMONEY)->count(),
'total_card_payments_count' => Transaction::where('type',PaymentGatewayConst::CARD_PAYMENT)->count(),
'total_support_ticket_count' => SupportTicket::all()->count(),
];
$transactions = Transaction::where('type',PaymentGatewayConst::CARD_PAYMENT)->latest()->take(5)->get();
return view('admin.sections.dashboard.index',compact(
'page_title',
'transactions',
'data',
));
}
/**
* Logout Admin From Dashboard
* @return view
*/
public function logout(Request $request) {
$admin = auth()->user();
pusher_unsubscribe("admin", $admin->id);
try{
$admin->update([
'last_logged_out' => now(),
'login_status' => false,
]);
}catch(Exception $e) {
// Handle Error
}
Auth::guard()->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect()->route('admin.login');
}
/**
* Function for clear admin notification
*/
public function notificationsClear() {
$admin = auth()->user();
if(!$admin) {
return false;
}
try{
$admin->update([
'notification_clear_at' => now(),
]);
}catch(Exception $e) {
$error = ['error' => ['Something went wrong! Please try again.']];
return Response::error($error,null,404);
}
$success = ['success' => ['Notifications clear successfully!']];
return Response::success($success,null,200);
}
}
Run Command [Bypass]
Run Command
User Login
top
In the digital age, privacy concerns have become increasingly paramount, prompting the European Union to enact the General Data Protection Regulation (GDPR) in 2018. Among its many provisions, GDPR sets strict guidelines for the collection and processing of personal data, including the use of cookies on websites. Privacy Policy
Allow
Decline