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/app/Http/Transformers/AssetModelsTransformer.php b/app/Http/Transformers/AssetModelsTransformer.php index 528df3b146..d694ac5b49 100644 --- a/app/Http/Transformers/AssetModelsTransformer.php +++ b/app/Http/Transformers/AssetModelsTransformer.php @@ -22,6 +22,22 @@ 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, + 'format' => e($field->format), + 'required' => ($field->pivot->required == '1') ? true : false, + ]; + } + } + $array = [ 'id' => (int) $assetmodel->id, 'name' => e($assetmodel->name), @@ -44,6 +60,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), 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/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); }); diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 0f6c78ee67..d7a3c03778 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 ((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']) + ->whereNotNull('company_id') + ->whereNotNull('location_id') + ->count('name'); + + return $count < 1; + } + else { + return true; + } + }); } /** 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", 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/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', diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index e7a87aed07..04f8d65303 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -43,12 +43,14 @@ 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.', '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.', diff --git a/resources/views/hardware/labels.blade.php b/resources/views/hardware/labels.blade.php index 02b212e1dd..b25b08a0a9 100644 --- a/resources/views/hardware/labels.blade.php +++ b/resources/views/hardware/labels.blade.php @@ -166,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 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') }}