Hide finance and admin KPIs from roles that lack them.
Deploy Ladill Care / deploy (push) Successful in 33s
Deploy Ladill Care / deploy (push) Successful in 33s
Doctors no longer see revenue, open bills, or org admin cards on the Care dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Member;
|
||||
use App\Services\Care\CarePermissions;
|
||||
use App\Services\Care\OrganizationResolver;
|
||||
use App\Services\Care\ReportService;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -17,6 +18,7 @@ class DashboardController extends Controller
|
||||
|
||||
public function __construct(
|
||||
protected ReportService $reports,
|
||||
protected CarePermissions $permissions,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
@@ -24,27 +26,57 @@ class DashboardController extends Controller
|
||||
$this->authorizeAbility($request, 'dashboard.view');
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
$member = $this->member($request);
|
||||
|
||||
$canBranches = $this->permissions->can($member, 'admin.branches.view');
|
||||
$canMembers = $this->permissions->can($member, 'admin.members.view');
|
||||
$canDepartments = $this->permissions->can($member, 'admin.departments.view');
|
||||
$canBills = $this->permissions->can($member, 'bills.view');
|
||||
$canFinance = $this->permissions->can($member, 'reports.finance.view');
|
||||
|
||||
$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' => $canBranches ? (clone $branchQuery)->where('is_active', true)->count() : 0,
|
||||
'team_members' => $canMembers
|
||||
? Member::owned($owner)->where('organization_id', $organization->id)->count()
|
||||
: 0,
|
||||
'departments' => $canDepartments
|
||||
? $organization->branches()
|
||||
->when(app(OrganizationResolver::class)->branchScope($member), function ($q, $branchId) {
|
||||
$q->where('id', $branchId);
|
||||
})
|
||||
->withCount('departments')
|
||||
->get()
|
||||
->sum('departments_count')
|
||||
: 0,
|
||||
];
|
||||
|
||||
$branches = (clone $branchQuery)->withCount('departments')->orderBy('name')->get();
|
||||
$branches = $canBranches
|
||||
? (clone $branchQuery)->withCount('departments')->orderBy('name')->get()
|
||||
: collect();
|
||||
|
||||
$branchScope = app(OrganizationResolver::class)->branchScope($this->member($request));
|
||||
$operational = $this->reports->dashboardStats($owner, $organization->id, $branchScope);
|
||||
$branchScope = app(OrganizationResolver::class)->branchScope($member);
|
||||
$operational = $this->reports->dashboardStats(
|
||||
$owner,
|
||||
$organization->id,
|
||||
$branchScope,
|
||||
includeBilling: $canBills || $canFinance,
|
||||
);
|
||||
|
||||
return view('care.dashboard', compact('organization', 'stats', 'branches', 'operational'));
|
||||
return view('care.dashboard', [
|
||||
'organization' => $organization,
|
||||
'member' => $member,
|
||||
'permissions' => $this->permissions,
|
||||
'stats' => $stats,
|
||||
'branches' => $branches,
|
||||
'operational' => $operational,
|
||||
'canBranches' => $canBranches,
|
||||
'canMembers' => $canMembers,
|
||||
'canDepartments' => $canDepartments,
|
||||
'canBills' => $canBills,
|
||||
'canFinance' => $canFinance,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user