From e0e63c4611ee076421dcc05c8290db2d422e255e Mon Sep 17 00:00:00 2001 From: sayliraut Date: Mon, 8 Jul 2024 15:55:58 +0530 Subject: [PATCH 01/23] changes --- .../RestaurantApi_Service.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Services/APIs/RestaurantService/RestaurantApi_Service.php b/app/Services/APIs/RestaurantService/RestaurantApi_Service.php index fdb4624..08405b4 100644 --- a/app/Services/APIs/RestaurantService/RestaurantApi_Service.php +++ b/app/Services/APIs/RestaurantService/RestaurantApi_Service.php @@ -40,28 +40,40 @@ class RestaurantApi_Service ->where('principal_xid', $userDetail->id) ->get(); - // $restaurantDetails = []; + $restaurantDetails = []; + $isActive = true; + $inactiveMessage = ""; foreach ($restaurantRoles as $restaurantRole) { $restaurant = ManageRestaurant::select('id', 'name', 'description', 'restaurant_id', 'address', 'image', 'bio', 'try_on_1', 'phone_number', 'try_on_2', 'try_on_3', 'try_on_4', 'exclusion', 'latitude', 'longtitude', 'is_active', 'created_by', 'modified_by', 'deleted_at', 'created_at', 'updated_at') ->where('id', $restaurantRole->restaurant_xid) - ->where('is_active', 1) ->first(); if ($restaurant) { $restaurant->image = ListingImageUrl('restaurant_images', $restaurant->image); $restaurant->description = strip_tags($restaurant->description); - // $restaurantDetails[] = $restaurant; + if ($restaurant->is_active == 0) { + $isActive = false; + $inactiveMessage = "Your restaurant is currently not participating in Cheers to the Season. Please reach out to contact@cheerstotheseason.com to re-enroll."; + } + + // Add restaurant details to the array + $restaurantDetails[] = $restaurant; } } // Construct response $response = [ 'user_detail' => $userDetail, - 'restaurant_details' => $restaurant, + 'restaurant_details' => $restaurantDetails, + 'is_active' => $isActive, ]; + if (!$isActive) { + $response['message'] = $inactiveMessage; + } + // Return JSON response with success message return jsonResponseWithSuccessMessageApi(__('auth.User_details_fetch'), $response, 200); } catch (Exception $ex) { @@ -74,6 +86,7 @@ class RestaurantApi_Service + public function updateRestaurantDetail($restIamId, $request) { try { From 69aa9acba863b75f54a15604adb089d6702985d8 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Mon, 8 Jul 2024 16:40:22 +0530 Subject: [PATCH 02/23] sales graph --- .../Controllers/Admin/DashboardController.php | 74 ++++++- resources/views/Admin/dashboard.blade.php | 193 +++++++++++++----- 2 files changed, 204 insertions(+), 63 deletions(-) diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 0480db5..1ef8bbb 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -17,14 +17,64 @@ class DashboardController extends Controller * Use : To show the dashboard. */ - // public function showDashboard(){ - - - // return view('Admin.dashboard'); - // } public function showDashboard() { - // Monthly data + + $dailyData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("DATE(created_at) as date")) + ->whereBetween('created_at', [now()->subDays(7), now()]) // Fetch data for the last 7 days + ->groupBy(DB::raw("DATE(created_at)")) + ->orderBy(DB::raw("DATE(created_at)")) + ->pluck('count', 'date') + ->toArray(); + + $start_date = now()->subDays(7)->startOfDay(); + $end_date = now()->endOfDay(); + $formattedDailyData = []; + while ($start_date <= $end_date) { + $formattedDailyData[$start_date->format('Y-m-d')] = isset($dailyData[$start_date->format('Y-m-d')]) ? $dailyData[$start_date->format('Y-m-d')] : 0; + $start_date->addDay(); + } + + + $defaultData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month")) + ->whereYear('created_at', date('Y')) + ->groupBy(DB::raw("MONTH(created_at)")) + ->orderBy(DB::raw("MONTH(created_at)")) + ->pluck('count', 'month') + ->toArray(); + + $months = range(1, 12); + $formattedDefaultData = []; + foreach ($months as $month) { + $formattedDefaultData[$month] = isset($defaultData[$month]) ? $defaultData[$month] : 0; + } + $quarterlyData = Subscriptions::select( + DB::raw("COUNT(*) as count"), + DB::raw("QUARTER(created_at) as quarter") + ) + ->whereYear('created_at', date('Y')) + ->groupBy(DB::raw("QUARTER(created_at)")) + ->orderBy(DB::raw("QUARTER(created_at)")) + ->pluck('count', 'quarter') + ->toArray(); + + // Ensure that $quarterlyData contains zeros for quarters with no data + for ($i = 1; $i <= 4; $i++) { + if (!isset($quarterlyData[$i])) { + $quarterlyData[$i] = 0; + } + } + + // Sort the array by quarter keys + ksort($quarterlyData); + + // Fetching data for yearly option + $yearlyData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year")) + ->groupBy(DB::raw("YEAR(created_at)")) + ->pluck('count', 'year') + ->toArray(); + + $dataMonthlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month")) ->where('principal_type_xid', 3) ->whereYear('created_at', date('Y')) @@ -78,7 +128,9 @@ class DashboardController extends Controller $customerCount = IamPrincipal::where('principal_type_xid', '=', 3)->count(); $restaurantCount = Subscriptions::where('is_active', 1)->count(); - $recent_transaction = Subscriptions::with('subscription')->get()->toArray(); + $dateTime = now(); + $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); + $recent_transaction = Subscriptions::where('next_payment_date', '>=', $formattedDateTime)->with('subscription')->get()->toArray(); return view('Admin.dashboard', compact( @@ -90,7 +142,13 @@ class DashboardController extends Controller 'dataQuarterlyWithType4', 'dataYearlyWithType3', 'dataYearlyWithType4', - 'recent_transaction' + 'recent_transaction', + 'dailyData', + 'formattedDailyData', + 'defaultData', + 'formattedDefaultData', + 'quarterlyData', + 'yearlyData' )); } } diff --git a/resources/views/Admin/dashboard.blade.php b/resources/views/Admin/dashboard.blade.php index 8e23a70..2f333c4 100644 --- a/resources/views/Admin/dashboard.blade.php +++ b/resources/views/Admin/dashboard.blade.php @@ -64,41 +64,38 @@
-
-
-
-
-
-
User Graph
- -
-
+
+
+
+
+
User Graph
+
+
- {{--
-
-
-
-
Sales Graph
- -
-
-
-
-
-
--}} - +
+
+
+
+
Sales Graph
+ +
+
+
+
+
@@ -346,7 +343,6 @@ }); }); - - + + }); + - - @endsection + } + + @endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index b42ab13..f286cdc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -61,6 +61,7 @@ Route::group(['middleware' => ['checkStatus']], function () { Route::get('/dashboard', [DashboardController::class, 'showDashboard'])->name('dashboard'); + Route::post('/export_recent_transaction', [DashboardController::class, 'exportRecentTransactions'])->name('export.recent.transactions'); Route::get('/profile', [ManageProfileController::class, 'index'])->name('profile'); Route::post('/update_profile', [ManageProfileController::class, 'update_profile'])->name('update.profile'); From d71d0d9dbc02efb613cca2688bf5f55c5db8d416 Mon Sep 17 00:00:00 2001 From: sayaliparab Date: Tue, 9 Jul 2024 12:46:01 +0530 Subject: [PATCH 05/23] RecentDash --- .../Controllers/Admin/DashboardController.php | 18 +++++++++- resources/views/Admin/dashboard.blade.php | 25 +------------ .../manage_reports/manage_reports.blade.php | 36 ++++++++++++++++--- routes/web.php | 2 +- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 6bc7793..755477c 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -162,12 +162,28 @@ class DashboardController extends Controller 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); + // } + // } + 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'); } diff --git a/resources/views/Admin/dashboard.blade.php b/resources/views/Admin/dashboard.blade.php index 019dbf6..9c62af1 100644 --- a/resources/views/Admin/dashboard.blade.php +++ b/resources/views/Admin/dashboard.blade.php @@ -105,7 +105,7 @@ $currentPage = 'dashboard';
Recent Transactions
-
+ @csrf @@ -343,30 +343,7 @@ $currentPage = 'dashboard'; '' + '').insertBefore("#zero-config_filter label"); -// Select/Deselect all checkboxes - // $('#select-all-ids').click(function() { - // $('input[name="customer_ids"]').prop('checked', this.checked); - // }); - // // Download all data - // $('#download_all').click(function() { - // window.location.href = '{{ route("export.recent.transactions") }}?all_id=true'; - // }); - - // // Download selected data - // $('#download-selected').click(function() { - // var selectedIds = []; - // $('input[name="customer_ids"]:checked').each(function() { - // selectedIds.push($(this).val()); - // }); - - // if (selectedIds.length > 0) { - // var ids = selectedIds.join(','); - // window.location.href = '{{ route("export.recent.transactions") }}?selected_id=' + ids; - // } else { - // alert('Please select at least one transaction to export.'); - // } - // }); $("#zero-config").on("click", ".sub_admin_permission", function() { var Name = $(this).data('name'); var Price = $(this).data('price'); diff --git a/resources/views/Admin/pages/manage_reports/manage_reports.blade.php b/resources/views/Admin/pages/manage_reports/manage_reports.blade.php index 373b538..d80d2a1 100644 --- a/resources/views/Admin/pages/manage_reports/manage_reports.blade.php +++ b/resources/views/Admin/pages/manage_reports/manage_reports.blade.php @@ -142,8 +142,37 @@ $currentPage = 'manage-reports'; }); }); - // Refresh page after download - document.getElementById('reportForm').addEventListener('submit', function() { + // Form validation before submission + document.getElementById('reportForm').addEventListener('submit', function(event) { + var selectedRadio = document.querySelector('input[name="reportType"]:checked'); + var selectedCheckboxes = document.querySelectorAll('.state-checkboxes.show .state-checkbox:checked'); + var startDate = document.getElementById("startDate").value; + var endDate = document.getElementById("endDate").value; + + if (!startDate) { + event.preventDefault(); // Prevent form submission + toastr.error('Please select a start date.'); + return; + } + + if (!endDate) { + event.preventDefault(); // Prevent form submission + toastr.error('Please select an end date.'); + return; + } + + if (!selectedRadio) { + event.preventDefault(); // Prevent form submission + toastr.error('Please select a report type.'); + return; + } + + if (selectedCheckboxes.length === 0) { + event.preventDefault(); // Prevent form submission + toastr.error('Please select at least one state or restaurant.'); + return; + } + // Add a timeout to ensure the form data is sent before refreshing setTimeout(function() { location.reload(); @@ -152,8 +181,7 @@ $currentPage = 'manage-reports';