From 70f44c825681f441e5d3963c94a759afe07602fc Mon Sep 17 00:00:00 2001 From: timiajayi Date: Wed, 7 Aug 2024 20:56:55 +0100 Subject: [PATCH 1/8] AdminDashboard --- .../Api/V1/Admin/AdminDashboardController.php | 73 +++++++++++++++++++ routes/api.php | 2 + 2 files changed, 75 insertions(+) create mode 100644 app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php diff --git a/app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php b/app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php new file mode 100644 index 00000000..ae6c5f4e --- /dev/null +++ b/app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php @@ -0,0 +1,73 @@ +startOfMonth(); + $lastMonth = now()->subMonth()->startOfMonth(); + + // Revenue statistics + $currentMonthRevenue = Order::where('created_at', '>=', $currentMonth) + ->sum('total_amount'); + $lastMonthRevenue = Order::whereBetween('created_at', [$lastMonth, $currentMonth]) + ->sum('total_amount'); + $revenuePercentageDifference = $this->calculatePercentageDifference($currentMonthRevenue, $lastMonthRevenue); + + // User statistics + $totalUsers = User::count(); + $lastMonthUsers = User::where('created_at', '<', $currentMonth)->count(); + $userPercentageDifference = $this->calculatePercentageDifference($totalUsers, $lastMonthUsers); + + // Product statistics + $totalProducts = Product::count(); + $lastMonthProducts = Product::where('created_at', '<', $currentMonth)->count(); + $productPercentageDifference = $this->calculatePercentageDifference($totalProducts, $lastMonthProducts); + + // Lifetime sales statistics + $lifetimeSales = Order::sum('total_amount'); + $lastMonthSales = Order::where('created_at', '<', $currentMonth)->sum('total_amount'); + $salesPercentageDifference = $this->calculatePercentageDifference($lifetimeSales, $lastMonthSales); + + return response()->json([ + 'message' => 'Dashboard statistics retrieved successfully', + 'status_code' => Response::HTTP_OK, + 'data' => [ + 'total_revenue' => [ + 'amount' => $currentMonthRevenue, + 'difference' => round($revenuePercentageDifference, 2) . '%' + ], + 'total_users' => [ + 'count' => $totalUsers, + 'difference' => round($userPercentageDifference, 2) . '%' + ], + 'total_products' => [ + 'count' => $totalProducts, + 'difference' => round($productPercentageDifference, 2) . '%' + ], + 'lifetime_sales' => [ + 'amount' => $lifetimeSales, + 'difference' => round($salesPercentageDifference, 2) . '%' + ], + ] + ]); + } + + private function calculatePercentageDifference($current, $previous) + { + if ($previous > 0 && $current > 0) { + return (($current - $previous) / $previous) * 100; + } elseif ($current > 0 && $previous === 0) { + return 100; + } + return 0; + } +} diff --git a/routes/api.php b/routes/api.php index f82c8bcc..104e272c 100755 --- a/routes/api.php +++ b/routes/api.php @@ -48,6 +48,7 @@ use App\Http\Controllers\Api\V1\SuperAdmin\SuperAdminProductController; use App\Http\Controllers\Api\V1\Organisation\OrganizationMemberController; +use App\Http\Controllers\Api\V1\Admin\AdminDashboardController; /* |-------------------------------------------------------------------------- | API Routes @@ -229,6 +230,7 @@ Route::get('/waitlists', [WaitListController::class, 'index']); Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); Route::get('/dashboard-cards', [DashboardController::class, 'index']); + Route::get('/statistics', [AdminDashboardController::class, 'getStatistics']); }); Route::post('/waitlists', [WaitListController::class, 'store']); From 024ac6102feeb34be6479b82ec596ba79d95f710 Mon Sep 17 00:00:00 2001 From: timiajayi Date: Wed, 7 Aug 2024 20:59:08 +0100 Subject: [PATCH 2/8] adminDashboard --- , | 0 Dashboard statistics retrieved successfully, | 0 "Response\357\200\272\357\200\272HTTP_OK," | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 , create mode 100644 Dashboard statistics retrieved successfully, create mode 100644 "Response\357\200\272\357\200\272HTTP_OK," diff --git a/, b/, new file mode 100644 index 00000000..e69de29b diff --git a/Dashboard statistics retrieved successfully, b/Dashboard statistics retrieved successfully, new file mode 100644 index 00000000..e69de29b diff --git "a/Response\357\200\272\357\200\272HTTP_OK," "b/Response\357\200\272\357\200\272HTTP_OK," new file mode 100644 index 00000000..e69de29b From 2c1055fe9d9b1252438805f96164b69e282bef86 Mon Sep 17 00:00:00 2001 From: timiajayi Date: Wed, 7 Aug 2024 21:16:40 +0100 Subject: [PATCH 3/8] adminDashboard cards --- .../Api/V1/Admin/AdminDashboardController.php | 21 +++++++++++------- routes/api.php | 22 +------------------ 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php b/app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php index ae6c5f4e..832694bd 100644 --- a/app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php +++ b/app/Http/Controllers/Api/V1/Admin/AdminDashboardController.php @@ -42,23 +42,28 @@ public function getStatistics() 'status_code' => Response::HTTP_OK, 'data' => [ 'total_revenue' => [ - 'amount' => $currentMonthRevenue, - 'difference' => round($revenuePercentageDifference, 2) . '%' + 'current_month' => $currentMonthRevenue, + 'previous_month' => $lastMonthRevenue, + 'percentage_difference' => round($revenuePercentageDifference, 2) . '%', ], 'total_users' => [ - 'count' => $totalUsers, - 'difference' => round($userPercentageDifference, 2) . '%' + 'current_month' => $totalUsers, + 'previous_month' => $lastMonthUsers, + 'percentage_difference' => round($userPercentageDifference, 2) . '%', ], 'total_products' => [ - 'count' => $totalProducts, - 'difference' => round($productPercentageDifference, 2) . '%' + 'current_month' => $totalProducts, + 'previous_month' => $lastMonthProducts, + 'percentage_difference' => round($productPercentageDifference, 2) . '%', ], 'lifetime_sales' => [ - 'amount' => $lifetimeSales, - 'difference' => round($salesPercentageDifference, 2) . '%' + 'current_month' => $lifetimeSales, + 'previous_month' => $lastMonthSales, + 'percentage_difference' => round($salesPercentageDifference, 2) . '%', ], ] ]); + } private function calculatePercentageDifference($current, $previous) diff --git a/routes/api.php b/routes/api.php index 6a2d8482..06a48420 100755 --- a/routes/api.php +++ b/routes/api.php @@ -45,26 +45,6 @@ use App\Http\Controllers\QuestController; use App\Http\Controllers\UserNotificationController; use Illuminate\Support\Facades\Route; - - -use App\Http\Controllers\Api\V1\Admin\DashboardController; -use App\Http\Controllers\Api\V1\Auth\SocialAuthController; -use App\Http\Controllers\Api\V1\User\ExportUserController; -use App\Http\Controllers\Api\V1\CookiePreferencesController; -use App\Http\Controllers\Api\V1\Admin\Plan\FeatureController; - - -use App\Http\Controllers\Api\V1\Admin\EmailTemplateController; -use App\Http\Controllers\Api\V1\Auth\ResetUserPasswordController; -use App\Http\Controllers\Api\V1\NotificationPreferenceController; -use App\Http\Controllers\Api\V1\Admin\Plan\SubscriptionController; -use App\Http\Controllers\Api\V1\Testimonial\TestimonialController; -use App\Http\Controllers\Api\V1\Auth\ForgotResetPasswordController; -use App\Http\Controllers\Api\V1\Organisation\OrganisationController; -use App\Http\Controllers\Api\V1\Auth\ForgetPasswordRequestController; - -use App\Http\Controllers\Api\V1\SuperAdmin\SuperAdminProductController; -use App\Http\Controllers\Api\V1\Organisation\OrganizationMemberController; use App\Http\Controllers\Api\V1\Admin\AdminDashboardController; /* |-------------------------------------------------------------------------- @@ -254,7 +234,7 @@ Route::delete('/blogs/{id}', [BlogController::class, 'destroy']); Route::get('/waitlists', [WaitListController::class, 'index']); Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); - Route::get('/dashboard-cards', [DashboardController::class, 'index']); + Route::get('/statistics', [AdminDashboardController::class, 'getStatistics']); }); Route::post('/waitlists', [WaitListController::class, 'store']); From 231543ff6c7054c289933e15177411bc2a03a4a3 Mon Sep 17 00:00:00 2001 From: timiajayi Date: Wed, 7 Aug 2024 21:34:45 +0100 Subject: [PATCH 4/8] adminDashboard cards --- resources/docs/documentation.json | 152 ++++++++++++++++++++++-------- 1 file changed, 115 insertions(+), 37 deletions(-) diff --git a/resources/docs/documentation.json b/resources/docs/documentation.json index b3b0f390..109f38ad 100644 --- a/resources/docs/documentation.json +++ b/resources/docs/documentation.json @@ -500,53 +500,131 @@ }, "/api/v1/statistics": { "get": { - "tags": [ - "Dashboard" - ], - "summary": "Get dashboard statistics", - "description": "Retrieve the statistics for the dashboard, including total revenue, subscriptions, and sales.", - "responses": { - "200": { - "description": "Successful operation", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/inline_response_200_5" + "tags": [ + "Admin Dashboard" + ], + "summary": "Get admin dashboard statistics", + "description": "Retrieve the statistics for the admin dashboard, including total revenue, users, products, and lifetime sales.", + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Dashboard statistics retrieved successfully" + }, + "status_code": { + "type": "integer", + "example": 200 + }, + "data": { + "type": "object", + "properties": { + "revenue": { + "type": "object", + "properties": { + "current_month": { + "type": "number", + "example": 45000 + }, + "previous_month": { + "type": "number", + "example": 37500 + }, + "percentage_difference": { + "type": "string", + "example": "20%" + } } }, - "application/xml": { - "schema": { - "$ref": "#/components/schemas/inline_response_200_5" + "users": { + "type": "object", + "properties": { + "current_month": { + "type": "integer", + "example": 4000 + }, + "previous_month": { + "type": "integer", + "example": 3636 + }, + "percentage_difference": { + "type": "string", + "example": "10%" } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/inline_response_400" } - } - } - }, - "500": { - "description": "Internal Server Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/inline_response_500_3" + }, + "products": { + "type": "object", + "properties": { + "current_month": { + "type": "integer", + "example": 1000 + }, + "previous_month": { + "type": "integer", + "example": 833 + }, + "percentage_difference": { + "type": "string", + "example": "20%" + } + } + }, + "lifetime_sales": { + "type": "object", + "properties": { + "current_month": { + "type": "number", + "example": 450000 + }, + "previous_month": { + "type": "number", + "example": 180000 + }, + "percentage_difference": { + "type": "string", + "example": "150%" + } } } + } } + } + } } + } }, - "security": [ - { - "bearerAuth": [] + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/inline_response_400" } - ] + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/inline_response_500_3" + } + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ] } }, "/api/v1/export/{format}": { From 25df35f1b78046f5a37516d3d81580af1b84b2ea Mon Sep 17 00:00:00 2001 From: Timiajayi <61969771+timiajayi@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:19:43 +0100 Subject: [PATCH 5/8] Update api.php Signed-off-by: Timiajayi <61969771+timiajayi@users.noreply.github.com> --- routes/api.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/routes/api.php b/routes/api.php index 06a48420..fee2b230 100755 --- a/routes/api.php +++ b/routes/api.php @@ -234,6 +234,11 @@ Route::delete('/blogs/{id}', [BlogController::class, 'destroy']); Route::get('/waitlists', [WaitListController::class, 'index']); Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); + + + + + Route::get('/statistics', [AdminDashboardController::class, 'getStatistics']); }); From 39393a8c0bf2424510e2b85575dab8e4fdc71bc1 Mon Sep 17 00:00:00 2001 From: Timiajayi <61969771+timiajayi@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:25:56 +0100 Subject: [PATCH 6/8] Update api.php Signed-off-by: Timiajayi <61969771+timiajayi@users.noreply.github.com> --- routes/api.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/routes/api.php b/routes/api.php index fee2b230..44d42163 100755 --- a/routes/api.php +++ b/routes/api.php @@ -234,12 +234,8 @@ Route::delete('/blogs/{id}', [BlogController::class, 'destroy']); Route::get('/waitlists', [WaitListController::class, 'index']); Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); - - - - - Route::get('/statistics', [AdminDashboardController::class, 'getStatistics']); + Route::apiResource('faqs', FaqController::class); }); Route::post('/waitlists', [WaitListController::class, 'store']); From 3bfea0ec91f5235bc8ae62bf9e23af73d90b9a4b Mon Sep 17 00:00:00 2001 From: Timiajayi <61969771+timiajayi@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:39:13 +0100 Subject: [PATCH 7/8] Update api.php Signed-off-by: Timiajayi <61969771+timiajayi@users.noreply.github.com> --- routes/api.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routes/api.php b/routes/api.php index 003737e4..edf9d8fa 100755 --- a/routes/api.php +++ b/routes/api.php @@ -239,8 +239,7 @@ Route::delete('/blogs/{id}', [BlogController::class, 'destroy']); Route::get('/waitlists', [WaitListController::class, 'index']); Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); - Route::get('/statistics', [AdminDashboardController::class, 'getStatistics']) - Route::apiResource('faqs', FaqController::class); + Route::get('/statistics', [AdminDashboardController::class, 'getStatistics']); }); Route::post('/waitlists', [WaitListController::class, 'store']); From e1897989226a8c2424e63efcaef2f9ff39336b34 Mon Sep 17 00:00:00 2001 From: Timiajayi <61969771+timiajayi@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:44:00 +0100 Subject: [PATCH 8/8] Update api.php Signed-off-by: Timiajayi <61969771+timiajayi@users.noreply.github.com> --- routes/api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/api.php b/routes/api.php index edf9d8fa..ce2da066 100755 --- a/routes/api.php +++ b/routes/api.php @@ -240,6 +240,7 @@ Route::get('/waitlists', [WaitListController::class, 'index']); Route::apiResource('squeeze-pages', SqueezePageCoontroller::class); Route::get('/statistics', [AdminDashboardController::class, 'getStatistics']); + Route::apiResource('faqs', FaqController::class); }); Route::post('/waitlists', [WaitListController::class, 'store']);