Files
cheerstothe_season_2.0/app/Http/Controllers/Admin/DashboardController.php

97 lines
3.6 KiB
PHP
Raw Normal View History

2024-05-23 15:20:21 +05:30
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
2024-05-29 14:53:06 +05:30
use App\Models\IamPrincipal;
use Illuminate\Support\Facades\DB;
use App\Models\ManageRestaurant;
2024-05-23 15:20:21 +05:30
class DashboardController extends Controller
{
2024-06-11 15:09:59 +05:30
/**
2024-06-05 20:10:10 +05:30
* Created By : sayali parab
* Created at : 16 May 2024
* Use : To show the dashboard.
*/
2024-05-29 14:53:06 +05:30
// public function showDashboard(){
2024-05-23 15:20:21 +05:30
2024-06-11 12:24:42 +05:30
2024-05-29 14:53:06 +05:30
// return view('Admin.dashboard');
// }
public function showDashboard()
{
// Monthly data
$dataMonthlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
2024-06-11 12:24:42 +05:30
->where('principal_type_xid', 3)
2024-05-29 14:53:06 +05:30
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
$dataMonthlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
2024-06-11 12:24:42 +05:30
->where('principal_type_xid', 4)
2024-05-29 14:53:06 +05:30
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
2024-06-11 12:24:42 +05:30
// Fill missing months with zeros
$months = range(1, 12);
$dataMonthlyWithType3 = array_replace(array_fill_keys($months, 0), $dataMonthlyWithType3);
$dataMonthlyWithType4 = array_replace(array_fill_keys($months, 0), $dataMonthlyWithType4);
2024-05-29 14:53:06 +05:30
// Quarterly data
2024-06-11 12:24:42 +05:30
$dataQuarterlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
->where('principal_type_xid', 3)
2024-05-29 14:53:06 +05:30
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
2024-06-11 12:24:42 +05:30
$dataQuarterlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
->where('principal_type_xid', 4)
2024-05-29 14:53:06 +05:30
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
2024-06-11 12:24:42 +05:30
// Fill missing quarters with zeros
$quarters = range(1, 4);
$dataQuarterlyWithType3 = array_replace(array_fill_keys($quarters, 0), $dataQuarterlyWithType3);
$dataQuarterlyWithType4 = array_replace(array_fill_keys($quarters, 0), $dataQuarterlyWithType4);
2024-05-29 14:53:06 +05:30
// Yearly data
$dataYearlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
2024-06-11 12:24:42 +05:30
->where('principal_type_xid', 3)
2024-05-29 14:53:06 +05:30
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
$dataYearlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
2024-06-11 12:24:42 +05:30
->where('principal_type_xid', 4)
2024-05-29 14:53:06 +05:30
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
$customerCount = IamPrincipal::where('principal_type_xid', '=', 3)->count();
$restaurantCount = ManageRestaurant::where('is_active', 1)->count();
2024-06-11 12:24:42 +05:30
return view('Admin.dashboard', compact(
2024-06-11 15:09:59 +05:30
'customerCount',
'restaurantCount',
'dataMonthlyWithType3',
'dataMonthlyWithType4',
'dataQuarterlyWithType3',
'dataQuarterlyWithType4',
'dataYearlyWithType3',
'dataYearlyWithType4'
2024-06-11 12:24:42 +05:30
));
}
2024-05-23 15:20:21 +05:30
}