From 339263a295bdc989f06ed57ca8c47379bc847108 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 5 Jul 2018 19:30:36 -0700 Subject: [PATCH] Fixed #5751 - added option for unique constraint on serial --- app/Http/Controllers/SettingsController.php | 1 + app/Http/Traits/UniqueSerialTrait.php | 23 +++++++++++++ app/Models/Asset.php | 6 ++-- ...0_add_unique_serial_option_to_settings.php | 32 +++++++++++++++++++ resources/lang/en/admin/settings/general.php | 2 ++ resources/views/settings/general.blade.php | 17 +++++++++- 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 app/Http/Traits/UniqueSerialTrait.php create mode 100644 database/migrations/2018_07_05_215440_add_unique_serial_option_to_settings.php diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 1557991c01..931addf24e 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -334,6 +334,7 @@ class SettingsController extends Controller $setting->full_multiple_companies_support = $request->input('full_multiple_companies_support', '0'); $setting->load_remote = $request->input('load_remote', '0'); + $setting->unique_serial = $request->input('unique_serial', '0'); $setting->show_images_in_email = $request->input('show_images_in_email', '0'); $setting->show_archived_in_list = $request->input('show_archived_in_list', '0'); $setting->dashboard_message = $request->input('dashboard_message'); diff --git a/app/Http/Traits/UniqueSerialTrait.php b/app/Http/Traits/UniqueSerialTrait.php new file mode 100644 index 0000000000..fc2291c7a3 --- /dev/null +++ b/app/Http/Traits/UniqueSerialTrait.php @@ -0,0 +1,23 @@ +unique_serial=='1') { + return 'unique_undeleted:'.$this->table.','. $this->getKey(); + } + + } +} diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 5595b2d2b1..92085b582f 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -2,6 +2,7 @@ namespace App\Models; use App\Exceptions\CheckoutNotAllowed; +use App\Http\Traits\UniqueSerialTrait; use App\Http\Traits\UniqueUndeletedTrait; use App\Presenters\Presentable; use AssetPresenter; @@ -23,7 +24,7 @@ use App\Notifications\CheckoutAssetNotification; class Asset extends Depreciable { protected $presenter = 'App\Presenters\AssetPresenter'; - use Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait; + use Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait, UniqueSerialTrait; const LOCATION = 'location'; const ASSET = 'asset'; @@ -72,12 +73,13 @@ class Asset extends Depreciable 'status_id' => 'required|integer|exists:status_labels,id', 'company_id' => 'integer|nullable', 'warranty_months' => 'numeric|nullable', - 'physical' => 'numeric|max:1|nullable', + 'physical' => 'numeric|max:1|nullable', 'checkout_date' => 'date|max:10|min:10|nullable', 'checkin_date' => 'date|max:10|min:10|nullable', 'supplier_id' => 'numeric|nullable', 'asset_tag' => 'required|min:1|max:255|unique_undeleted', 'status' => 'integer', + 'serial' => 'unique_serial|nullable', 'purchase_cost' => 'numeric|nullable', 'next_audit_date' => 'date|nullable', 'last_audit_date' => 'date|nullable', diff --git a/database/migrations/2018_07_05_215440_add_unique_serial_option_to_settings.php b/database/migrations/2018_07_05_215440_add_unique_serial_option_to_settings.php new file mode 100644 index 0000000000..eeaeb79279 --- /dev/null +++ b/database/migrations/2018_07_05_215440_add_unique_serial_option_to_settings.php @@ -0,0 +1,32 @@ +boolean('unique_serial')->default('0'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('unique_serial'); + }); + } +} diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index fb68f12205..177041b181 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -179,5 +179,7 @@ return array( 'bottom' => 'bottom', 'vertical' => 'vertical', 'horizontal' => 'horizontal', + 'unique_serial' => 'Unique serial numbers', + 'unique_serial_help_text' => 'Checking this box will enforce a uniqeness constraint on asset serials', 'zerofill_count' => 'Length of asset tags, including zerofill', ); diff --git a/resources/views/settings/general.blade.php b/resources/views/settings/general.blade.php index 0f5012e5eb..174d173afa 100644 --- a/resources/views/settings/general.blade.php +++ b/resources/views/settings/general.blade.php @@ -137,8 +137,23 @@ + +
+
+ {{ Form::label('unique_serial', trans('admin/settings/general.unique_serial')) }} +
+
+ {{ Form::checkbox('unique_serial', '1', Input::old('unique_serial', $setting->unique_serial),array('class' => 'minimal')) }} + {{ trans('general.yes') }} + {!! $errors->first('unique_serial', ':message') !!} +

+ {{ trans('admin/settings/general.unique_serial_help_text') }} +

+
+
- + +
{{ Form::label('per_page', trans('admin/settings/general.per_page')) }}