A free open source IT asset/license management system
Allow custom report to filter on assigned/unassigned
snipe17a88fcb8058
diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.phpindex ded8b7d746..b904aece9f 100644--- a/app/Http/Controllers/ReportsController.php+++ b/app/Http/Controllers/ReportsController.php@@ -798,6 +798,14 @@ class ReportsController extends Controller$assets->onlyTrashed();}+ if ($request->input('assignment_status') === 'assigned') {+ $assets->whereNotNull('assets.assigned_to');+ }++ if ($request->input('assignment_status') === 'unassigned') {+ $assets->whereNull('assets.assigned_to');+ }+$assets->orderBy('assets.id', 'ASC')->chunk(500, function ($assets) use ($handle, $customfields, $request) {$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];diff --git a/app/Http/Requests/CustomAssetReportRequest.php b/app/Http/Requests/CustomAssetReportRequest.phpindex 8cf28d2dd5..c2018a16a0 100644--- a/app/Http/Requests/CustomAssetReportRequest.php+++ b/app/Http/Requests/CustomAssetReportRequest.php@@ -29,6 +29,7 @@ class CustomAssetReportRequest extends Requestpublic function rules(){return [+ 'assignment_status' => 'nullable|in:all,assigned,unassigned','purchase_start' => 'date|date_format:Y-m-d|nullable','purchase_end' => 'date|date_format:Y-m-d|nullable','purchase_cost_end' => 'numeric|nullable|gte:purchase_cost_start',diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.phpindex af8693090f..705b9e8d13 100644--- a/resources/views/reports/custom.blade.php+++ b/resources/views/reports/custom.blade.php@@ -629,6 +629,42 @@</label></div>+ <div class="col-md-9 col-md-offset-3">+ <label class="form-control">+ <input+ name="assignment_status"+ id="assignment_status_all"+ type="radio"+ value="all"+ @checked($template->radioValue('assignment_status', 'all', true))+ aria-label="assignment_status"+ >+ {{ trans('general.all') }} {{ trans('general.assigned') }} / {{ trans('general.unassigned') }}+ </label>+ <label class="form-control">+ <input+ name="assignment_status"+ id="assignment_status_assigned"+ type="radio"+ value="assigned"+ @checked($template->radioValue('assignment_status', 'assigned'))+ aria-label="assignment_status"+ >+ {{ trans('general.assigned') }}+ </label>+ <label class="form-control">+ <input+ name="assignment_status"+ id="assignment_status_unassigned"+ type="radio"+ value="unassigned"+ @checked($template->radioValue('assignment_status', 'unassigned'))+ aria-label="assignment_status"+ >+ {{ trans('general.unassigned') }}+ </label>+ </div>+<div class="col-md-9 col-md-offset-3"><label class="form-control"><inputdiff --git a/tests/Feature/Reporting/CustomReportTest.php b/tests/Feature/Reporting/CustomReportTest.phpindex bce61a6f45..77e6a9aca6 100644--- a/tests/Feature/Reporting/CustomReportTest.php+++ b/tests/Feature/Reporting/CustomReportTest.php@@ -177,6 +177,36 @@ class CustomReportTest extends TestCase implements TestsPermissionsRequirement->assertDontSeeTextInStreamedResponse('Asset E');}+ public function test_can_limit_custom_report_to_assigned_assets(): void+ {+ Asset::factory()->assignedToUser()->create(['name' => 'Assigned Asset']);+ Asset::factory()->create(['name' => 'Unassigned Asset']);++ $this->actingAs(User::factory()->canViewReports()->create())+ ->post('reports/custom', [+ 'asset_name' => '1',+ 'assignment_status' => 'assigned',+ ])+ ->assertOk()+ ->assertSeeTextInStreamedResponse('Assigned Asset')+ ->assertDontSeeTextInStreamedResponse('Unassigned Asset');+ }++ public function test_can_limit_custom_report_to_unassigned_assets(): void+ {+ Asset::factory()->assignedToUser()->create(['name' => 'Assigned Asset']);+ Asset::factory()->create(['name' => 'Unassigned Asset']);++ $this->actingAs(User::factory()->canViewReports()->create())+ ->post('reports/custom', [+ 'asset_name' => '1',+ 'assignment_status' => 'unassigned',+ ])+ ->assertOk()+ ->assertDontSeeTextInStreamedResponse('Assigned Asset')+ ->assertSeeTextInStreamedResponse('Unassigned Asset');+ }+public function test_custom_report_decrypts_encrypted_custom_fields_when_user_has_permission(): void{$customField = CustomField::factory()->encrypt()->create();