A free open source IT asset/license management system
Show child companies in company view sidebar
sniped207f7ddd4b9
diff --git a/app/Http/Controllers/CompaniesController.php b/app/Http/Controllers/CompaniesController.phpindex 6562718549..ac3a778091 100644--- a/app/Http/Controllers/CompaniesController.php+++ b/app/Http/Controllers/CompaniesController.php@@ -173,6 +173,10 @@ final class CompaniesController extends Controller{$this->authorize('view', Company::class);+ // Eager-load the hierarchy so the sidebar's parent + children list+ // doesn't trigger lazy lookups during render.+ $company->loadMissing('parent', 'children');+// Counts on the tab badges include hierarchy (the row + parent + children)// to match the tab contents the API serves under expand_company_hierarchy=1.// Computed here so the Blade can stay free of @php blocks.diff --git a/resources/lang/en-US/admin/companies/table.php b/resources/lang/en-US/admin/companies/table.phpindex 752f2b1b26..e63045885c 100644--- a/resources/lang/en-US/admin/companies/table.php+++ b/resources/lang/en-US/admin/companies/table.php@@ -14,4 +14,5 @@ return ['children' => 'Child Companies','inherited' => 'Inherited','inherited_help' => 'This item belongs to a related company in the hierarchy (parent or child), not this company directly.',+ 'hierarchy' => 'Company Hierarchy',];diff --git a/resources/views/companies/view.blade.php b/resources/views/companies/view.blade.phpindex 6916a2661e..3de17eeec1 100644--- a/resources/views/companies/view.blade.php+++ b/resources/views/companies/view.blade.php@@ -84,6 +84,28 @@</x-info-panel></x-box>++ @if ($company->parent || $company->children->isNotEmpty())+ <x-box>+ <h2 class="box-title" style="font-size: 16px; margin-bottom: 12px;">{{ trans('admin/companies/table.hierarchy') }}</h2>++ @if ($company->parent)+ <p style="margin-bottom: 12px;">+ <strong>{{ trans('admin/companies/table.parent') }}:</strong><br>+ <a href="{{ route('companies.show', $company->parent) }}">{{ $company->parent->name }}</a>+ </p>+ @endif++ @if ($company->children->isNotEmpty())+ <p style="margin-bottom: 4px;"><strong>{{ trans('admin/companies/table.children') }}:</strong></p>+ <ul style="padding-left: 20px; margin-bottom: 0;">+ @foreach ($company->children->sortBy('name') as $child)+ <li><a href="{{ route('companies.show', $child) }}">{{ $child->name }}</a></li>+ @endforeach+ </ul>+ @endif+ </x-box>+ @endif</x-page-column></x-container>diff --git a/tests/Feature/Companies/Ui/ShowCompanyTest.php b/tests/Feature/Companies/Ui/ShowCompanyTest.phpindex 9df4705cd8..956d7152fd 100644--- a/tests/Feature/Companies/Ui/ShowCompanyTest.php+++ b/tests/Feature/Companies/Ui/ShowCompanyTest.php@@ -28,4 +28,42 @@ class ShowCompanyTest extends TestCaseroute('companies.show', $child),]);}++ public function test_sidebar_shows_children_for_parent_company()+ {+ $parent = Company::factory()->create(['name' => 'Parent Sidebar Co']);+ $childA = Company::factory()->childOf($parent)->create(['name' => 'Aardvark Subsidiary']);+ $childB = Company::factory()->childOf($parent)->create(['name' => 'Zebra Subsidiary']);+ $unrelated = Company::factory()->create(['name' => 'Unrelated Co']);++ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('companies.show', $parent))+ ->assertOk()+ ->assertSee(trans('admin/companies/table.hierarchy'))+ ->assertSee($childA->name)+ ->assertSee($childB->name)+ ->assertDontSee($unrelated->name);+ }++ public function test_sidebar_shows_parent_for_child_company()+ {+ $parent = Company::factory()->create(['name' => 'Top Level Sidebar Co']);+ $child = Company::factory()->childOf($parent)->create(['name' => 'Subsidiary Sidebar Co']);++ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('companies.show', $child))+ ->assertOk()+ ->assertSee(trans('admin/companies/table.hierarchy'))+ ->assertSee($parent->name);+ }++ public function test_sidebar_hierarchy_box_hidden_when_company_is_standalone()+ {+ $solo = Company::factory()->create(['name' => 'Standalone Sidebar Co']);++ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('companies.show', $solo))+ ->assertOk()+ ->assertDontSee(trans('admin/companies/table.hierarchy'));+ }}