From 92ae27129213876b1107c21b61dc04bede55fc36 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 9 Nov 2022 13:11:33 -0800 Subject: [PATCH 01/11] adds validation for department names at Company locations --- app/Models/Department.php | 2 +- app/Providers/ValidationServiceProvider.php | 19 +++++++++++++++++++ .../lang/en/admin/departments/message.php | 1 + resources/lang/en/validation.php | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Models/Department.php b/app/Models/Department.php index 7be99d097b..74e2b23df9 100644 --- a/app/Models/Department.php +++ b/app/Models/Department.php @@ -29,7 +29,7 @@ class Department extends SnipeModel ]; protected $rules = [ - 'name' => 'required|max:255', + 'name' => 'required|max:255|is_unique_department', 'location_id' => 'numeric|nullable', 'company_id' => 'numeric|nullable', 'manager_id' => 'numeric|nullable', diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 0f6c78ee67..1f11303cab 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -2,8 +2,10 @@ namespace App\Providers; +use App\Models\Department; use DB; use Illuminate\Support\ServiceProvider; +use Illuminate\Validation\Rule; use Validator; /** @@ -213,6 +215,23 @@ class ValidationServiceProvider extends ServiceProvider return true; } }); + + Validator::extend('is_unique_department', function ($attribute, $value, $parameters, $validator) { + $data = $validator->getData(); + if ($data['location_id'] != null && $data['company_id'] != null) { + $count = Department::where('name', $data['name']) + ->where('location_id', $data['location_id']) + ->where('company_id', $data['company_id']) + ->whereNotNull('company_id') + ->whereNotNull('location_id') + ->count('name'); + + return $count < 1; + } + else { + return true; + } + }); } /** diff --git a/resources/lang/en/admin/departments/message.php b/resources/lang/en/admin/departments/message.php index d65f4fbb2b..2e371348b9 100644 --- a/resources/lang/en/admin/departments/message.php +++ b/resources/lang/en/admin/departments/message.php @@ -3,6 +3,7 @@ return array( 'does_not_exist' => 'Department does not exist.', + 'department_already_exists' => 'A department already exists with that name at this company location. Or choose a more specific name for this department. ', 'assoc_users' => 'This department is currently associated with at least one user and cannot be deleted. Please update your users to no longer reference this department and try again. ', 'create' => array( 'error' => 'Department was not created, please try again.', diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index e7a87aed07..367df4db45 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -49,6 +49,7 @@ return [ 'ip' => 'The :attribute must be a valid IP address.', 'ipv4' => 'The :attribute must be a valid IPv4 address.', 'ipv6' => 'The :attribute must be a valid IPv6 address.', + 'is_unique_department' => 'The :attribute must be unique to this Company Location', 'json' => 'The :attribute must be a valid JSON string.', 'max' => [ 'numeric' => 'The :attribute may not be greater than :max.', From 38575e93e8441bd42d4318cc7619b4227bdefae3 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 20 Dec 2022 09:45:41 -0800 Subject: [PATCH 02/11] fixes the rules for adding page-break and padding at the end of document --- resources/views/hardware/labels.blade.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/views/hardware/labels.blade.php b/resources/views/hardware/labels.blade.php index 98318d0fac..97d25295bd 100644 --- a/resources/views/hardware/labels.blade.php +++ b/resources/views/hardware/labels.blade.php @@ -52,7 +52,6 @@ $qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->alt_barcode!='') } img.barcode { display:block; - padding-top: .11in; width: 100%; } @@ -167,9 +166,9 @@ $qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->alt_barcode!='') - @if ($count % $settings->labels_per_page == 0) -
-
 
+ @if (($count % $settings->labels_per_page == 0) && $count!=count($assets)) +
+
 
@endif @endforeach From e791e6592a8dd994522d23bfa2faa46150bfa030 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 20 Dec 2022 10:37:19 -0800 Subject: [PATCH 03/11] adds notes to the accessories tab under users --- resources/views/users/view.blade.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index b220e25592..5d959589e6 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -750,18 +750,20 @@ }'> - {{ trans('general.name') }} - {{ trans('general.purchase_cost') }} - {{ trans('general.action') }} + {{ trans('general.name') }} + {{ trans('general.notes') }} + {{ trans('general.purchase_cost') }} + {{ trans('general.action') }} @foreach ($user->accessories as $accessory) {!!$accessory->present()->nameUrl()!!} - + {!! $accessory->pivot->note !!} + {!! Helper::formatCurrencyOutput($accessory->purchase_cost) !!} - + @can('checkin', $accessory) {{ trans('general.checkin') }} From fa439a19284c4a7f52d458608429826e05051933 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 3 Jan 2023 14:45:23 -0800 Subject: [PATCH 04/11] Check that the array key exists before trying to seed it Signed-off-by: snipe --- app/Providers/ValidationServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 1f11303cab..d7a3c03778 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -218,7 +218,7 @@ class ValidationServiceProvider extends ServiceProvider Validator::extend('is_unique_department', function ($attribute, $value, $parameters, $validator) { $data = $validator->getData(); - if ($data['location_id'] != null && $data['company_id'] != null) { + if ((array_key_exists('location_id', $data) && $data['location_id'] != null) && (array_key_exists('company_id', $data) && $data['company_id'] != null)) { $count = Department::where('name', $data['name']) ->where('location_id', $data['location_id']) ->where('company_id', $data['company_id']) From c4f900e9af8df9bf8dfc7b5e003b8fc7d7876b2e Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Wed, 4 Jan 2023 13:02:53 -0800 Subject: [PATCH 05/11] Change license_seat changing method to properly 'true up' license seats --- app/Models/License.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Models/License.php b/app/Models/License.php index d0e6f5c969..b59387a42e 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -123,12 +123,20 @@ class License extends Depreciable static::created(function ($license) { $newSeatCount = $license->getAttributes()['seats']; - return static::adjustSeatCount($license, $oldSeatCount = 0, $newSeatCount); + return static::adjustSeatCount($license, 0, $newSeatCount); }); // However, we listen for updating to be able to prevent the edit if we cannot delete enough seats. static::updating(function ($license) { $newSeatCount = $license->getAttributes()['seats']; - $oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0; + //$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0; + /* + That previous method *did* mostly work, but if you ever managed to get your $license->seats value out of whack + with your actual count of license_seats *records*, you would never manage to get back 'into whack'. + The below method actually grabs a count of existing license_seats records, so it will be more accurate. + This means that if your license_seats are out of whack, you can change the quantity and hit 'save' and it + will manage to 'true up' and make your counts line up correctly. + */ + $oldSeatCount = $license->license_seats_count; return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount); }); From b77d5801faaed6d4ddf626da8e9df0c1e1b8f1f1 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 4 Jan 2023 13:56:16 -0800 Subject: [PATCH 06/11] English is hard, apparently Signed-off-by: snipe --- resources/lang/en/admin/settings/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index 701cf695fb..d41deaf935 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -21,7 +21,7 @@ return [ 'allow_user_skin_help_text' => 'Checking this box will allow a user to override the UI skin with a different one.', 'asset_ids' => 'Asset IDs', 'audit_interval' => 'Audit Interval', - 'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months that you use. If you update this value, all of the "next audit dates" for assets with an upcoming audit date.', + 'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months that you use. If you update this value, all of the "next audit dates" for assets with an upcoming audit date will be updated.', 'audit_warning_days' => 'Audit Warning Threshold', 'audit_warning_days_help' => 'How many days in advance should we warn you when assets are due for auditing?', 'auto_increment_assets' => 'Generate auto-incrementing asset tags', From 7123e7327fe4ddc5ea5651bf5be5d7244ddf4f04 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 4 Jan 2023 14:00:04 -0800 Subject: [PATCH 07/11] Updated less-loader and css-loader libraries Signed-off-by: snipe --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 079a5c7538..1f6eaa93e2 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "bootstrap-less": "^3.3.8", "bootstrap-table": "1.20.2", "chart.js": "^2.9.4", - "css-loader": "^3.6.0", + "css-loader": "^4.0.0", "ekko-lightbox": "^5.1.1", "icheck": "^1.0.2", "imagemin": "^8.0.1", @@ -47,7 +47,7 @@ "jquery.iframe-transport": "^1.0.0", "jspdf-autotable": "^3.5.24", "less": "^4.1.2", - "less-loader": "^5.0.0", + "less-loader": "^6.0.0", "list.js": "^1.5.0", "papaparse": "^4.3.3", "select2": "4.0.13", From 9c63f426d973a3c4fb12530de5a0e80eb085dc43 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 4 Jan 2023 14:09:14 -0800 Subject: [PATCH 08/11] Added missing translation string Signed-off-by: snipe --- app/Http/Requests/ItemImportRequest.php | 2 +- resources/lang/en/validation.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/ItemImportRequest.php b/app/Http/Requests/ItemImportRequest.php index f42b45a625..d360beaf29 100644 --- a/app/Http/Requests/ItemImportRequest.php +++ b/app/Http/Requests/ItemImportRequest.php @@ -49,7 +49,7 @@ class ItemImportRequest extends FormRequest $errorMessage = null; if (is_null($fieldValue)) { - $errorMessage = trans('validation.import_field_empty'); + $errorMessage = trans('validation.import_field_empty', ['fieldname' => $field]); $this->errorCallback($import, $field, $errorMessage); return $this->errors; diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 367df4db45..04f8d65303 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -43,6 +43,7 @@ return [ 'file' => 'The :attribute must be a file.', 'filled' => 'The :attribute field must have a value.', 'image' => 'The :attribute must be an image.', + 'import_field_empty' => 'The value for :fieldname cannot be null.', 'in' => 'The selected :attribute is invalid.', 'in_array' => 'The :attribute field does not exist in :other.', 'integer' => 'The :attribute must be an integer.', From 301c4fda6e81eecbe4abb9c0f89b28662fa05b1f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 5 Jan 2023 09:55:25 -0800 Subject: [PATCH 09/11] fixes conflicts --- resources/views/hardware/labels.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/hardware/labels.blade.php b/resources/views/hardware/labels.blade.php index 97d25295bd..b25b08a0a9 100644 --- a/resources/views/hardware/labels.blade.php +++ b/resources/views/hardware/labels.blade.php @@ -52,7 +52,7 @@ $qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->alt_barcode!='') } img.barcode { display:block; - padding-top: .11in; + margin-top:-7px; width: 100%; } div.label-logo { From db43628bdc04c0e3723daccc8f92666faeafdc24 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 5 Jan 2023 13:12:54 -0800 Subject: [PATCH 10/11] Added default field info to models API response Signed-off-by: snipe --- app/Http/Transformers/AssetModelsTransformer.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Http/Transformers/AssetModelsTransformer.php b/app/Http/Transformers/AssetModelsTransformer.php index 528df3b146..5b51709963 100644 --- a/app/Http/Transformers/AssetModelsTransformer.php +++ b/app/Http/Transformers/AssetModelsTransformer.php @@ -22,6 +22,21 @@ class AssetModelsTransformer public function transformAssetModel(AssetModel $assetmodel) { + + $default_field_values = array(); + + // Reach into the custom fields and models_custom_fields pivot table to find the default values for this model + if ($assetmodel->fieldset) { + foreach($assetmodel->fieldset->fields AS $field) { + $default_field_values[] = [ + 'name' => e($field->name), + 'db_column_name' => e($field->db_column_name()), + 'default_value' => ($field->defaultValue($assetmodel->id)) ? e($field->defaultValue($assetmodel->id)) : null, + 'required' => ($field->pivot->required == '1') ? true : false, + ]; + } + } + $array = [ 'id' => (int) $assetmodel->id, 'name' => e($assetmodel->name), @@ -44,6 +59,7 @@ class AssetModelsTransformer 'id' => (int) $assetmodel->fieldset->id, 'name'=> e($assetmodel->fieldset->name), ] : null, + 'default_fieldset_values' => $default_field_values, 'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None', 'requestable' => ($assetmodel->requestable == '1') ? true : false, 'notes' => e($assetmodel->notes), From 381f89c5a82395d957cde9c61d9d51a281cca808 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 5 Jan 2023 13:15:30 -0800 Subject: [PATCH 11/11] Added format to array Signed-off-by: snipe --- app/Http/Transformers/AssetModelsTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Transformers/AssetModelsTransformer.php b/app/Http/Transformers/AssetModelsTransformer.php index 5b51709963..d694ac5b49 100644 --- a/app/Http/Transformers/AssetModelsTransformer.php +++ b/app/Http/Transformers/AssetModelsTransformer.php @@ -32,6 +32,7 @@ class AssetModelsTransformer 'name' => e($field->name), 'db_column_name' => e($field->db_column_name()), 'default_value' => ($field->defaultValue($assetmodel->id)) ? e($field->defaultValue($assetmodel->id)) : null, + 'format' => e($field->format), 'required' => ($field->pivot->required == '1') ? true : false, ]; }