Files
ladill-care/app/Http/Controllers/Care/DashboardController.php
T
isaaccladandCursor 6c9c742ed8
Deploy Ladill Care / deploy (push) Failing after 13s
Initial Ladill Care release.
Healthcare management app: patients, appointments, consultations, lab,
pharmacy inventory, billing, and reports at care.ladill.com.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 11:36:22 +00:00

51 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers\Care;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Models\Member;
use App\Services\Care\OrganizationResolver;
use App\Services\Care\ReportService;
use Illuminate\Http\Request;
use Illuminate\View\View;
class DashboardController extends Controller
{
use ScopesToAccount;
public function __construct(
protected ReportService $reports,
) {}
public function index(Request $request): View
{
$this->authorizeAbility($request, 'dashboard.view');
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$branchQuery = Branch::owned($owner)->where('organization_id', $organization->id);
$this->scopeToBranch($request, $branchQuery);
$stats = [
'branches' => (clone $branchQuery)->where('is_active', true)->count(),
'team_members' => Member::owned($owner)->where('organization_id', $organization->id)->count(),
'departments' => $organization->branches()
->when(app(OrganizationResolver::class)->branchScope($this->member($request)), function ($q, $branchId) {
$q->where('id', $branchId);
})
->withCount('departments')
->get()
->sum('departments_count'),
];
$branches = (clone $branchQuery)->withCount('departments')->orderBy('name')->get();
$branchScope = app(OrganizationResolver::class)->branchScope($this->member($request));
$operational = $this->reports->dashboardStats($owner, $organization->id, $branchScope);
return view('care.dashboard', compact('organization', 'stats', 'branches', 'operational'));
}
}