From ee4b8f4694972d4b4eefa6a2857bba1bfec20606 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:03:31 -0800 Subject: [PATCH 01/10] Added byod to API controller Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 21e393bb89..dae0d8c22b 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -100,6 +100,7 @@ class AssetsController extends Controller 'checkout_counter', 'checkin_counter', 'requests_counter', + 'byod', ]; $filter = []; @@ -189,6 +190,10 @@ class AssetsController extends Controller $assets->ByDepreciationId($request->input('depreciation_id')); } + if ($request->filled('byod')) { + $assets->ByDepreciationId($request->input('byod')); + } + $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : ''; // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which From b80d52a9c3a7e6582d76768e33a95b1ef46cfcbb Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:03:51 -0800 Subject: [PATCH 02/10] Added byod to asset controller for create and update methods Signed-off-by: snipe --- app/Http/Controllers/Assets/AssetsController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index c845b2cc76..1c7080bd46 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -146,6 +146,7 @@ class AssetsController extends Controller $asset->supplier_id = request('supplier_id', null); $asset->requestable = request('requestable', 0); $asset->rtd_location_id = request('rtd_location_id', null); + $asset->byod = request('byod', 0); if (! empty($settings->audit_interval)) { $asset->next_audit_date = Carbon::now()->addMonths($settings->audit_interval)->toDateString(); @@ -318,6 +319,7 @@ class AssetsController extends Controller // If the box isn't checked, it's not in the request at all. $asset->requestable = $request->filled('requestable'); $asset->rtd_location_id = $request->input('rtd_location_id', null); + $asset->byod = $request->input('byod', 0); if ($asset->assigned_to == '') { $asset->location_id = $request->input('rtd_location_id', null); From f62641350258f648508da7cd4740d478b08c0b64 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:04:02 -0800 Subject: [PATCH 03/10] Added byod to API transformer Signed-off-by: snipe --- app/Http/Transformers/AssetsTransformer.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index 9dfc6d4e7a..a36d0ab89b 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -35,6 +35,8 @@ class AssetsTransformer 'id' => (int) $asset->model->id, 'name'=> e($asset->model->name), ] : null, + 'byod' => ($asset->byod ? true : false), + 'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null, 'eol' => ($asset->purchase_date != '') ? Helper::getFormattedDateObject($asset->present()->eol_date(), 'date') : null, 'status_label' => ($asset->assetstatus) ? [ From 48b8cfcef98f171417f573bce59112e5c46d492e Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:04:36 -0800 Subject: [PATCH 04/10] Added byod to model, removed duplicate validation rule Signed-off-by: snipe --- app/Models/Asset.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index d42461a23f..266285677f 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -95,6 +95,7 @@ class Asset extends Depreciable 'location_id' => 'integer', 'rtd_company_id' => 'integer', 'supplier_id' => 'integer', + 'byod' => 'boolean', ]; protected $rules = [ @@ -106,7 +107,6 @@ class Asset extends Depreciable 'physical' => 'numeric|max:1|nullable', 'checkout_date' => 'date|max:10|min:10|nullable', 'checkin_date' => 'date|max:10|min:10|nullable', - 'supplier_id' => 'exists:suppliers,id|numeric|nullable', 'location_id' => 'exists:locations,id|nullable', 'rtd_location_id' => 'exists:locations,id|nullable', 'asset_tag' => 'required|min:1|max:255|unique_undeleted', @@ -144,6 +144,7 @@ class Asset extends Depreciable 'requestable', 'last_checkout', 'expected_checkin', + 'byod', ]; use Searchable; From acd182e3d23cc544addf0157e2ba10f7d9e0df43 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:10:30 -0800 Subject: [PATCH 05/10] Added byod to presenter with boolean formatter Signed-off-by: snipe --- app/Presenters/AssetPresenter.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index 5db653c7cb..ccc4a4cf13 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -250,6 +250,14 @@ class AssetPresenter extends Presenter 'visible' => false, 'title' => trans('general.next_audit_date'), 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'byod', + 'searchable' => false, + 'sortable' => true, + 'visible' => false, + 'title' => trans('general.byod'), + 'formatter' => 'trueFalseFormatter', + ], ]; From 45019c65f11159ce150eabd3a566f186c89fd099 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:10:39 -0800 Subject: [PATCH 06/10] BYOD migration Signed-off-by: snipe --- .../2023_01_18_122534_add_byod_to_assets.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 database/migrations/2023_01_18_122534_add_byod_to_assets.php diff --git a/database/migrations/2023_01_18_122534_add_byod_to_assets.php b/database/migrations/2023_01_18_122534_add_byod_to_assets.php new file mode 100644 index 0000000000..63c4b70623 --- /dev/null +++ b/database/migrations/2023_01_18_122534_add_byod_to_assets.php @@ -0,0 +1,34 @@ +boolean('byod')->nullable()->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('assets', function (Blueprint $table) { + if (Schema::hasColumn('assets', 'byod')) { + $table->dropColumn('byod'); + } + }); + } +} From 33fe2b57f7e1b414f92145cedb53e88945d2fdf5 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:10:48 -0800 Subject: [PATCH 07/10] Added new byod strings Signed-off-by: snipe --- resources/lang/en/general.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index f0b6a3f2cf..acc00501ed 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -39,6 +39,8 @@ return [ 'bulk_delete' => 'Bulk Delete', 'bulk_actions' => 'Bulk Actions', 'bulk_checkin_delete' => 'Bulk Checkin Items from Users', + 'byod' => 'BYOD', + 'byod_help' => 'This device is owned by the user', 'bystatus' => 'by Status', 'cancel' => 'Cancel', 'categories' => 'Categories', From fce620b54fef4a368ccd646e12b10a77ad3fbcb1 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:11:02 -0800 Subject: [PATCH 08/10] Added byod to blades Signed-off-by: snipe --- resources/views/hardware/edit.blade.php | 13 +++++++++++++ resources/views/hardware/view.blade.php | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index ed01db3071..07c04d7f8b 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -120,6 +120,19 @@
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')]) @include ('partials.forms.edit.warranty') + + +
+
+ +

{{ trans('general.byod_help') }} +

+
+
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 27b410e802..70f25fdca1 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -289,7 +289,6 @@ @endif - @if ((isset($audit_log)) && ($audit_log->created_at))
@@ -438,6 +437,16 @@
+ +
+
+ {{ trans('general.byod') }} +
+
+ {!! ($asset->byod=='1') ? ' '.trans('general.yes') : ' '.trans('general.no') !!} +
+
+ @if (($asset->model) && ($asset->model->fieldset)) @foreach($asset->model->fieldset->fields as $field)
From 0c39c7a53d981771d59a9c9548450c9f023b3bf6 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 13:25:46 -0800 Subject: [PATCH 09/10] =?UTF-8?q?Updated=20blades=20to=20add=20byod=20as?= =?UTF-8?q?=20a=20=E2=80=9Cstatus=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 5 +++++ app/Http/Middleware/AssetCountForSidebar.php | 7 +++++++ resources/views/hardware/index.blade.php | 2 ++ resources/views/layouts/default.blade.php | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index dae0d8c22b..b8675a4131 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -271,6 +271,11 @@ class AssetsController extends Controller // more sad, horrible workarounds for laravel bugs when doing full text searches $assets->where('assets.assigned_to', '>', '0'); break; + case 'byod': + // This is kind of redundant, since we already check for byod=1 above, but this keeps the + // sidebar nav links a little less chaotic + $assets->where('assets.byod', '=', '1'); + break; default: if ((! $request->filled('status_id')) && ($settings->show_archived_in_list != '1')) { diff --git a/app/Http/Middleware/AssetCountForSidebar.php b/app/Http/Middleware/AssetCountForSidebar.php index 414c10e8a1..5d9656f5c1 100644 --- a/app/Http/Middleware/AssetCountForSidebar.php +++ b/app/Http/Middleware/AssetCountForSidebar.php @@ -52,6 +52,13 @@ class AssetCountForSidebar \Log::debug($e); } + try { + $total_byod_sidebar = Asset::where('byod', '=', '1')->count(); + view()->share('total_byod_sidebar', $total_byod_sidebar); + } catch (\Exception $e) { + \Log::debug($e); + } + return $next($request); } } diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index ef095c1cef..a73b37f2ce 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -25,6 +25,8 @@ {{ trans('general.archived') }} @elseif (Request::get('status')=='Deleted') {{ trans('general.deleted') }} + @elseif (Request::get('status')=='byod') + {{ trans('general.byod') }} @endif @else {{ trans('general.all') }} diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index f332b6578e..daf4275481 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -454,6 +454,12 @@ ({{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }}) + + {{ trans('general.all') }} + {{ trans('general.byod') }} + ({{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }}) + + {{ trans('general.all') }} {{ trans('admin/hardware/general.archived') }} From 378dc968b785167c0d5a0797b18275f70931add6 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Jan 2023 15:44:28 -0800 Subject: [PATCH 10/10] Derp. Copypasta Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index b8675a4131..a843aa09db 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -191,7 +191,7 @@ class AssetsController extends Controller } if ($request->filled('byod')) { - $assets->ByDepreciationId($request->input('byod')); + $assets->where('assets.byod', '=', $request->input('byod')); } $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : '';