Skip to content

Commit

Permalink
generate impact report
Browse files Browse the repository at this point in the history
  • Loading branch information
xlcrr committed Sep 20, 2024
1 parent 2fa28c9 commit 8c28a6a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 30 deletions.
62 changes: 62 additions & 0 deletions app/Http/Controllers/Reports/GenerateImpactReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Http\Controllers\Reports;

use Carbon\Carbon;
use App\Models\Photo;
use App\Models\User\User;
use Illuminate\View\View;
use App\Models\Location\Country;
use App\Http\Controllers\Controller;

class GenerateImpactReportController extends Controller
{
/**
* Generate a weekly impact report
*/
public function __invoke (): View
{
$start = now()->startOfWeek();
$end = now()->endOfWeek();

// Mon 1st Sept 2024 - Sun 7th Sept 2024
$startDate = Carbon::parse($start)->format('D jS M Y');
$endDate = Carbon::parse($end)->format('D jS M Y');

$newUsers = User::whereDate('created_at', '>=', $start)
->whereDate('created_at', '<=', $end)
->count();
$totalUsers = User::count();

$newPhotos = Photo::whereDate('created_at', '>=', $start)
->whereDate('created_at', '<=', $end)
->count();
$totalPhotos = Photo::count();

$newTags = Photo::whereDate('created_at', '>=', $start)
->whereDate('created_at', '<=', $end)
->sum('total_litter');

$totalTags = 0;

$countries = Country::where('manual_verify', true)
->orderBy('country', 'asc')
->get();

foreach ($countries as $country)
{
$totalTags += $country->total_litter_redis;
}

return view('reports.impact', [
'startDate' => $startDate,
'endDate' => $endDate,
'newUsers' => $newUsers,
'totalUsers' => $totalUsers,
'newPhotos' => $newPhotos,
'totalPhotos' => $totalPhotos,
'newTags' => $newTags,
'totalTags' => $totalTags,
]);
}
}
3 changes: 1 addition & 2 deletions resources/views/reports/impact.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
padding: 0;
}
.container {
width: 100%;
max-width: 1200px;
width: 1080px;
margin: 0 auto;
padding: 20px;
}
Expand Down
29 changes: 1 addition & 28 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,7 @@

use Illuminate\Support\Facades\Route;

Route::get('test', function () {

// Mon 1st Sept 2024
$startDate = \Carbon\Carbon::parse('2024-09-01')->format('D jS M Y');

// Sun 7th Sept 2024
$endDate = \Carbon\Carbon::parse('2024-09-07')->format('D jS M Y');

$newUsers = 10;
$totalUsers = 8000;

$newPhotos = 20;
$totalPhotos = 50000;

$newTags = 100;
$totalTags = 200000;

return view('reports.impact', [
'startDate' => $startDate,
'endDate' => $endDate,
'newUsers' => $newUsers,
'totalUsers' => $totalUsers,
'newPhotos' => $newPhotos,
'totalPhotos' => $totalPhotos,
'newTags' => $newTags,
'totalTags' => $totalTags,
]);
});
Route::get('impact', 'Reports\GenerateImpactReportController');

Route::get('/', 'HomeController@index');
Route::get('/about', 'HomeController@index');
Expand Down

0 comments on commit 8c28a6a

Please sign in to comment.