can('petty-cash.view') || $user->can('petty-cash.update'); } /** * Determine whether the user can view the petty cash request. */ public function view(User $user, PettyCash $pettyCash): bool { if ($user->tenant_id !== $pettyCash->tenant_id) { return false; } if ($user->can('petty-cash.view') || $user->can('petty-cash.update')) { return true; } // Users can view their own petty cash requests return $pettyCash->requested_by === $user->id; } /** * Determine whether the user can create petty cash requests. */ public function create(User $user): bool { return $user->can('petty-cash.create'); } /** * Determine whether the user can update the petty cash request. */ public function update(User $user, PettyCash $pettyCash): bool { if ($user->tenant_id !== $pettyCash->tenant_id) { return false; } // Only pending requests can be updated if ($pettyCash->status !== 'pending') { return false; } if ($user->can('petty-cash.update')) { return true; } // Users can update their own pending requests return $pettyCash->requested_by === $user->id && $user->can('petty-cash.create'); } /** * Determine whether the user can delete the petty cash request. */ public function delete(User $user, PettyCash $pettyCash): bool { return $user->tenant_id === $pettyCash->tenant_id && $user->can('petty-cash.delete'); } /** * Determine whether the user can approve the petty cash request. * Only users with approve permission can approve. */ public function approve(User $user, PettyCash $pettyCash): bool { return $user->tenant_id === $pettyCash->tenant_id && $user->can('petty-cash.approve'); } }