Fixed #5751 - added option for unique constraint on serial

This commit is contained in:
snipe 2018-07-05 19:30:36 -07:00
parent a44bd9abe0
commit 339263a295
6 changed files with 78 additions and 3 deletions

View file

@ -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');

View file

@ -0,0 +1,23 @@
<?php
namespace App\Http\Traits;
trait UniqueSerialTrait
{
/**
* Prepare a unique_ids rule, adding a model identifier if required.
*
* @param array $parameters
* @param string $field
* @return string
*/
protected function prepareUniqueSerialRule($parameters, $field)
{
$settings = \App\Models\Setting::first();
if ($settings->unique_serial=='1') {
return 'unique_undeleted:'.$this->table.','. $this->getKey();
}
}
}

View file

@ -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';
@ -78,6 +79,7 @@ class Asset extends Depreciable
'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',

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUniqueSerialOptionToSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->boolean('unique_serial')->default('0');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('unique_serial');
});
}
}

View file

@ -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',
);

View file

@ -137,6 +137,21 @@
</div>
</div>
<!-- unique serial -->
<div class="form-group">
<div class="col-md-3">
{{ Form::label('unique_serial', trans('admin/settings/general.unique_serial')) }}
</div>
<div class="col-md-9">
{{ Form::checkbox('unique_serial', '1', Input::old('unique_serial', $setting->unique_serial),array('class' => 'minimal')) }}
{{ trans('general.yes') }}
{!! $errors->first('unique_serial', '<span class="alert-msg">:message</span>') !!}
<p class="help-block">
{{ trans('admin/settings/general.unique_serial_help_text') }}
</p>
</div>
</div>
<!-- Per Page -->
<div class="form-group {{ $errors->has('per_page') ? 'error' : '' }}">