diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 8bbc4a1..cc714a0 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -34,7 +34,7 @@ class DashboardController extends Controller ->orderBy(DB::raw("DATE(created_at)")) ->pluck('count', 'date') ->toArray(); - $customReferralCode = CustomReferralCode::where('is_active',1)->first(); + $customReferralCode = CustomReferralCode::where('is_active', 1)->first(); $start_date = now()->subDays(7)->startOfDay(); $end_date = now()->endOfDay(); @@ -148,28 +148,48 @@ class DashboardController extends Controller 'next_payment_date' => $transaction->next_payment_date ? Carbon::parse($transaction->next_payment_date)->format('m/d/Y') : null, ]; })->toArray(); - $refrralUsers = ReferralUsers::with(['referredUser','refeersUser'])->latest()->get(); + $response = ReferralUsers::with(['referredUser', 'refeersUser'])->latest()->get()->toArray(); - return view('Admin.dashboard', compact( - 'customReferralCode', - 'customerCount', - 'restaurantCount', - 'dataMonthlyWithType3', - 'dataMonthlyWithType4', - 'dataQuarterlyWithType3', - 'dataQuarterlyWithType4', - 'dataYearlyWithType3', - 'dataYearlyWithType4', - 'formatted_transactions', - 'dailyData', - 'formattedDailyData', - 'defaultData', - 'formattedDefaultData', - 'quarterlyData', - 'yearlyData', - 'refrralUsers' - ) + $referralData = []; + + foreach ($response as $item) { + $principalId = $item['iam_principal_xid']; + + if (!isset($referralData[$principalId])) { + $referralData[$principalId] = [ + 'referred_user' => $item['referred_user'], + 'refeers_users' => [] + ]; + } + + // Add the refeers_user to the respective principalId + if (isset($item['refeers_user'])) { + $referralData[$principalId]['refeers_users'][] = $item['refeers_user']; + } + } + + return view( + 'Admin.dashboard', + compact( + 'customReferralCode', + 'customerCount', + 'restaurantCount', + 'dataMonthlyWithType3', + 'dataMonthlyWithType4', + 'dataQuarterlyWithType3', + 'dataQuarterlyWithType4', + 'dataYearlyWithType3', + 'dataYearlyWithType4', + 'formatted_transactions', + 'dailyData', + 'formattedDailyData', + 'defaultData', + 'formattedDefaultData', + 'quarterlyData', + 'yearlyData', + 'referralData' + ) ); } @@ -188,19 +208,17 @@ class DashboardController extends Controller try { DB::beginTransaction(); - if($request->id){ + if ($request->id) { CustomReferralCode::updateOrCreate(['id', $request->id], [ 'referral_code' => $request->referral_code, ]); - }else{ - CustomReferralCode::updateOrCreate([ - 'referral_code' => $request->referral_code, - ]); - } + } else { + CustomReferralCode::updateOrCreate([ + 'referral_code' => $request->referral_code, + ]); + } DB::commit(); return response()->json(['status_code' => 200]); - - } catch (\Exception $e) { DB::rollBack(); \Log::error('Storing Referral Code function failed: ' . $e->getMessage()); diff --git a/resources/views/Admin/dashboard.blade.php b/resources/views/Admin/dashboard.blade.php index 110b26f..05b5889 100644 --- a/resources/views/Admin/dashboard.blade.php +++ b/resources/views/Admin/dashboard.blade.php @@ -18,40 +18,44 @@
- @if(!$customReferralCode ) -
- {{ csrf_field() }} -
Create Custom Referral Code:- - -
+ @if (!$customReferralCode) + + {{ csrf_field() }} +
Create Custom Referral Code:- - -
- -
+
-
+ +
+ +
+ + @endif - @if($customReferralCode && $customReferralCode->referral_code) -
- {{ csrf_field() }} -
My Custom Referral Code:- - -
+ @if ($customReferralCode && $customReferralCode->referral_code) + + {{ csrf_field() }} +
My Custom Referral Code:- - - -
- - - -
+
-
+ + +
+ + + +
+ + @endif
@@ -161,8 +165,8 @@
- +
Sr no @@ -191,7 +195,8 @@ {{ $transaction['subscription']['id'] ?? 'Deleted User' }} - $ {{ $transaction['amount'] ?? 'Deleted User' }} + $ + {{ $transaction['amount'] ?? 'Deleted User' }} {{ $transaction['status'] ?? 'Deleted User' }} @@ -269,9 +274,117 @@
- @endsection - @section('section_script') +
+
+
+
+
Referral Users
+
+ @csrf + + +
+ + + + + + + + + + + + + @foreach ($referralData as $principalId => $data) + + + + + + + + + @endforeach + + + + +
+
+ +
+
Sr noNameEmailCountReferred Users
+
+ +
+
{{ $loop->iteration }}{{ $data['referred_user']['first_name'] }} + {{ $data['referred_user']['last_name'] }}{{ $data['referred_user']['email_address'] }} + {{ count($data['refeers_users']) }} + + + View + +
+
+
+
+
+
+
+ + + + + + + +@endsection + +@section('section_script') - - + + + }); + - - @endsection + } + + function getUserChartCategories(filter) { + switch (filter) { + case 'monthly': + return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + case 'quarterly': + return ['Q1', 'Q2', 'Q3', 'Q4']; + case 'yearly': + return ; + default: + return []; + } + } + +@endsection