A free open source IT asset/license management system
Add manufacturer and model number to output
Marcus Moore244ef8ac3e73
diff --git a/app/Http/Controllers/Reports/CustomComponentReportController.php b/app/Http/Controllers/Reports/CustomComponentReportController.phpindex 5b6fd30aa0..ba08ed4be5 100644--- a/app/Http/Controllers/Reports/CustomComponentReportController.php+++ b/app/Http/Controllers/Reports/CustomComponentReportController.php@@ -62,21 +62,32 @@ class CustomComponentReportController extends Controller->with(['category','company',+ 'manufacturer',]);- $simpleConstraints = [+ $localConstraints = [+ 'by_model_number' => 'components.model_number',+ ];++ foreach ($localConstraints as $formKey => $column) {+ if ($request->filled($formKey)) {+ $components->where($column, $request->input($formKey));+ }+ }++ $foreignConstraints = ['by_company_id' => 'components.company_id','by_category_id' => 'components.category_id',+ 'by_manufacturer_id' => 'components.manufacturer_id',];- foreach ($simpleConstraints as $formKey => $column) {+ foreach ($foreignConstraints as $formKey => $column) {if ($request->filled($formKey)) {$components->whereIn($column, $request->input($formKey));}}$components->orderBy('components.id', 'ASC')->chunk(500, function ($components) use ($handle, $request) {-Log::debug('Walking results: '.$this->getExecutionTime());$count = 0;@@ -103,6 +114,14 @@ class CustomComponentReportController extends Controller$row[] = $component->name;}+ if ($request->filled('manufacturer')) {+ $row[] = $component?->manufacturer?->name;+ }++ if ($request->filled('model')) {+ $row[] = $component->model_number;+ }+// CSV_ESCAPE_FORMULAS is set to false in the .envif (config('app.escape_formulas') === false) {fputcsv($handle, $row);diff --git a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php b/tests/Feature/Reporting/Custom/CustomComponentReportTest.phpindex f2e1d1b95f..de2f1365a1 100644--- a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php+++ b/tests/Feature/Reporting/Custom/CustomComponentReportTest.php@@ -212,8 +212,6 @@ class CustomComponentReportTest extends TestCasepublic function test_limiting_by_manufacturer(){- $this->markTestIncomplete();-[$manufacturerA, $manufacturerB] = Manufacturer::factory()->count(2)->create()->all();Component::factory()@@ -237,6 +235,22 @@ class CustomComponentReportTest extends TestCase->assertDontSeeTextInStreamedResponse('Component for Manufacturer B');}+ public function test_limiting_by_model_number()+ {+ Component::factory()->create(['model_number' => 'MODEL-001']);+ Component::factory()->create(['model_number' => 'MODEL-002']);++ $this->sendRequest([+ 'component_name' => '1',+ 'model' => '1',+ 'by_model_number' => 'MODEL-001',+ ])+ ->assertOk()+ ->assertCsvHeader()+ ->assertSeeTextInStreamedResponse('MODEL-001')+ ->assertDontSeeTextInStreamedResponse('MODEL-002');+ }+public function test_limiting_by_supplier(){$this->markTestIncomplete();@@ -308,24 +322,6 @@ class CustomComponentReportTest extends TestCase->assertDontSeeTextInStreamedResponse('Hard Drive');}- public function test_limiting_by_model_number()- {- $this->markTestIncomplete();-- Component::factory()->create(['model_number' => 'MODEL-001']);- Component::factory()->create(['model_number' => 'MODEL-002']);-- $this->sendRequest([- 'component_name' => '1',- 'model' => '1',- 'by_model_number' => 'MODEL-001',- ])- ->assertOk()- ->assertCsvHeader()- ->assertSeeTextInStreamedResponse('MODEL-001')- ->assertDontSeeTextInStreamedResponse('MODEL-002');- }-public function test_limiting_by_order_number(){$this->markTestIncomplete();