Skip to content

A free open source IT asset/license management system

Zerofilling for auto-increment

snipeeb508901c5cb
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index 470e892d00..0ea1ca226d 100755
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -348,6 +348,7 @@ class SettingsController extends Controller
$setting->qr_text = e(Input::get('qr_text'));
$setting->auto_increment_prefix = e(Input::get('auto_increment_prefix'));
$setting->auto_increment_assets = e(Input::get('auto_increment_assets', '0'));
+ $setting->zerofill_count = e(Input::get('zerofill_count'));
$setting->alert_interval = e(Input::get('alert_interval'));
$setting->alert_threshold = e(Input::get('alert_threshold'));
$setting->email_domain = e(Input::get('email_domain'));
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 0fa8e30ffd..12f82cfce6 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -466,13 +466,24 @@ class Asset extends Depreciable
$asset_tag = \DB::table('assets')
->where('physical', '=', '1')
->max('id');
+
+ if ($settings->zerofill_count > 0) {
+ return $settings->auto_increment_prefix.Asset::zerofill(($asset_tag + 1),$settings->zerofill_count);
+ }
return $settings->auto_increment_prefix.($asset_tag + 1);
} else {
return false;
}
}
- public function checkin_email()
+
+ public static function zerofill ($num, $zerofill = 3)
+ {
+ return str_pad($num, $zerofill, '0', STR_PAD_LEFT);
+ }
+
+
+public function checkin_email()
{
return $this->model->category->checkin_email;
}
diff --git a/database/migrations/2016_07_27_211034_add_zerofill_to_settings.php b/database/migrations/2016_07_27_211034_add_zerofill_to_settings.php
new file mode 100644
index 0000000000..f560c74a4d
--- /dev/null
+++ b/database/migrations/2016_07_27_211034_add_zerofill_to_settings.php
@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddZerofillToSettings extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('settings', function (Blueprint $table) {
+ $table->integer('zerofill_count')->default(0);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('settings', function ($table) {
+ $table->dropColumn('zerofill_count');
+ });
+ }
+}
diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php
index d944955e6a..623b000605 100644
--- a/resources/lang/en/admin/settings/general.php
+++ b/resources/lang/en/admin/settings/general.php
@@ -108,4 +108,5 @@ return array(
'bottom' => 'bottom',
'vertical' => 'vertical',
'horizontal' => 'horizontal',
+ 'zerofill_count' => 'Length of asset tags, including zerofill',
);
diff --git a/resources/views/settings/edit.blade.php b/resources/views/settings/edit.blade.php
index 39a3303125..cd704bc164 100755
--- a/resources/views/settings/edit.blade.php
+++ b/resources/views/settings/edit.blade.php
@@ -304,6 +304,18 @@
</div>
</div>
+ <!-- auto zerofill -->
+ <div class="form-group {{ $errors->has('zerofill_count') ? 'error' : '' }}">
+ <div class="col-md-3">
+ {{ Form::label('auto_increment_prefix', trans('admin/settings/general.zerofill_count')) }}
+ </div>
+ <div class="col-md-9">
+ {{ Form::text('zerofill_count', Input::old('zerofill_count', $setting->zerofill_count), array('class' => 'form-control', 'style'=>'width: 100px;')) }}
+ {!! $errors->first('zerofill_count', '<span class="alert-msg">:message</span>') !!}
+
+ </div>
+ </div>
+
</div>
</div>
</div>