Premier commit
This commit is contained in:
54
app/Http/Controllers/DashboardController.php
Normal file
54
app/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Contract;
|
||||
use App\Models\AuditLog;
|
||||
use App\Models\GlobalSetting;
|
||||
use App\Models\Link;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the dashboard.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$contractStats = [
|
||||
'total' => Contract::count(),
|
||||
'active' => Contract::active()->count(),
|
||||
'expiring_soon' => Contract::expiringSoon(30)->count(),
|
||||
'expired' => Contract::where('status', 'expired')->count(),
|
||||
'by_type' => Contract::select('type', \DB::raw('count(*) as count'))->groupBy('type')->get()->keyBy('type'),
|
||||
];
|
||||
|
||||
// Recent logs
|
||||
$recentLogs = AuditLog::with('user')->latest()->take(10)->get();
|
||||
|
||||
// Upcoming Contracts (Timeline)
|
||||
$upcomingContracts = Contract::whereNotNull('end_date')
|
||||
->whereDate('end_date', '>=', now())
|
||||
->orderBy('end_date', 'asc')
|
||||
->take(6)
|
||||
->get();
|
||||
|
||||
// Dashboard Note
|
||||
$dashboardNote = GlobalSetting::get('dashboard_note');
|
||||
|
||||
// External Links
|
||||
$links = Link::active()->get();
|
||||
|
||||
return view('dashboard', compact('contractStats', 'recentLogs', 'upcomingContracts', 'dashboardNote', 'links'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the dashboard note.
|
||||
*/
|
||||
public function updateNote(Request $request)
|
||||
{
|
||||
GlobalSetting::set('dashboard_note', $request->input('note'));
|
||||
|
||||
return back()->with('success', 'Pense-bête mis à jour.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user