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-07-05 19:46:27 +05:30
|
|
|
use App\Models\Subscriptions;
|
2024-07-08 20:11:31 +05:30
|
|
|
use App\Exports\DashboardExportUser;
|
|
|
|
|
use App\Exports\DashboardSelectedExportUser;
|
|
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
|
|
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();
|
|
|
|
|
|
2024-07-05 19:46:27 +05:30
|
|
|
$dataMonthlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
|
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
|
|
|
|
2024-07-05 19:46:27 +05:30
|
|
|
$dataQuarterlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
|
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();
|
|
|
|
|
|
2024-07-05 19:46:27 +05:30
|
|
|
$dataYearlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
|
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();
|
2024-07-05 19:46:27 +05:30
|
|
|
$restaurantCount = Subscriptions::where('is_active', 1)->count();
|
|
|
|
|
$recent_transaction = Subscriptions::with('subscription')->get()->toArray();
|
|
|
|
|
|
2024-05-29 14:53:06 +05:30
|
|
|
|
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',
|
2024-07-05 19:46:27 +05:30
|
|
|
'dataYearlyWithType4',
|
|
|
|
|
'recent_transaction'
|
2024-06-11 12:24:42 +05:30
|
|
|
));
|
|
|
|
|
}
|
2024-07-08 20:11:31 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Created By : Sayali Parab
|
|
|
|
|
Created at : 08 July 2024
|
|
|
|
|
Use : To Get Excel.
|
|
|
|
|
*/
|
|
|
|
|
public function exportRecentTransactions(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if ($request->has('all_id')) {
|
|
|
|
|
$recentTransaction = Subscriptions::with('subscription')->get()->toArray();
|
|
|
|
|
// return $recentTransaction;
|
|
|
|
|
return Excel::download(new DashboardExportUser($recentTransaction), 'recent_transactions.xlsx');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ids = $request->input('selected_id');
|
|
|
|
|
$fileName = 'selected_customer_transaction_data.xlsx';
|
|
|
|
|
return Excel::download(new DashboardSelectedExportUser($ids), $fileName);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return response()->json(['error' => 'Export failed. Something went wrong.'], 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-23 15:20:21 +05:30
|
|
|
}
|
2024-07-08 20:11:31 +05:30
|
|
|
|