diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index de4f040f83..6c2474dd21 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -93,7 +93,7 @@ class AssetsController extends AdminController // Grab the dropdown list of status - $statuslabel_list = array('' => Lang::get('general.pending')) + array('0' => Lang::get('general.ready_to_deploy')) + Statuslabel::orderBy('name', 'asc')->lists('name', 'id'); + $statuslabel_list = Statuslabel::orderBy('name', 'asc')->lists('name', 'id'); $view = View::make('backend/hardware/edit'); $view->with('supplier_list',$supplier_list); @@ -238,7 +238,7 @@ class AssetsController extends AdminController $location_list = array('' => '') + Location::orderBy('name', 'asc')->lists('name', 'id'); // Grab the dropdown list of status - $statuslabel_list = array('' => Lang::get('general.pending')) + array('0' => Lang::get('general.ready_to_deploy')) + Statuslabel::orderBy('name', 'asc')->lists('name', 'id'); + $statuslabel_list = Statuslabel::orderBy('name', 'asc')->lists('name', 'id'); return View::make('backend/hardware/edit', compact('asset'))->with('model_list',$model_list)->with('supplier_list',$supplier_list)->with('location_list',$location_list)->with('statuslabel_list',$statuslabel_list); } @@ -589,7 +589,7 @@ class AssetsController extends AdminController $model_list = array('' => '') + Model::lists('name', 'id'); // Grab the dropdown list of status - $statuslabel_list = array('' => 'Pending') + array('0' => 'Ready to Deploy') + Statuslabel::lists('name', 'id'); + $statuslabel_list = Statuslabel::lists('name', 'id'); $location_list = array('' => '') + Location::lists('name', 'id'); diff --git a/app/controllers/admin/StatuslabelsController.php b/app/controllers/admin/StatuslabelsController.php index 9e6868c495..0185052e43 100755 --- a/app/controllers/admin/StatuslabelsController.php +++ b/app/controllers/admin/StatuslabelsController.php @@ -38,7 +38,12 @@ class StatuslabelsController extends AdminController public function getCreate() { // Show the page - return View::make('backend/statuslabels/edit')->with('statuslabel',new Statuslabel); + $statuslabel = new Statuslabel; + $use_statuslabel_type = $statuslabel->getStatuslabelType(); + + $statuslabel_types = array('' => Lang::get('admin/hardware/form.select_statustype')) + array('undeployable' => Lang::get('admin/hardware/general.undeployable')) + array('pending' => Lang::get('admin/hardware/general.pending')) + array('archived' => Lang::get('admin/hardware/general.archived')) + array('deployable' => Lang::get('admin/hardware/general.deployable')); + + return View::make('backend/statuslabels/edit', compact('statuslabel_types','statuslabel'))->with('use_statuslabel_type',$use_statuslabel_type); } @@ -59,9 +64,15 @@ class StatuslabelsController extends AdminController // attempt validation if ($statuslabel->validate($new)) { + $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types')); + // Save the Statuslabel data $statuslabel->name = e(Input::get('name')); $statuslabel->user_id = Sentry::getId(); + $statuslabel->notes = e(Input::get('notes')); + $statuslabel->deployable = $statustype['deployable']; + $statuslabel->pending = $statustype['pending']; + $statuslabel->archived = $statustype['archived']; // Was the asset created? if($statuslabel->save()) { @@ -94,8 +105,11 @@ class StatuslabelsController extends AdminController return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.does_not_exist')); } + $use_statuslabel_type = $statuslabel->getStatuslabelType(); - return View::make('backend/statuslabels/edit', compact('statuslabel')); + $statuslabel_types = array('' => Lang::get('admin/hardware/form.select_statustype')) + array('undeployable' => Lang::get('admin/hardware/general.undeployable')) + array('pending' => Lang::get('admin/hardware/general.pending')) + array('archived' => Lang::get('admin/hardware/general.archived')) + array('deployable' => Lang::get('admin/hardware/general.deployable')); + + return View::make('backend/statuslabels/edit', compact('statuslabel','statuslabel_types'))->with('use_statuslabel_type',$use_statuslabel_type); } @@ -118,20 +132,27 @@ class StatuslabelsController extends AdminController if ($validator->fails()) { - // The given data did not pass validation + // The given data did not pass validation return Redirect::back()->withInput()->withErrors($validator->messages()); } // attempt validation else { // Update the Statuslabel data + $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types')); + $statuslabel->name = e(Input::get('name')); + $statuslabel->notes = e(Input::get('notes')); + $statuslabel->deployable = $statustype['deployable']; + $statuslabel->pending = $statustype['pending']; + $statuslabel->archived = $statustype['archived']; + // Was the asset created? if($statuslabel->save()) { // Redirect to the saved Statuslabel page return Redirect::to("admin/settings/statuslabels/")->with('success', Lang::get('admin/statuslabels/message.update.success')); } - } + } // Redirect to the Statuslabel management page return Redirect::to("admin/settings/statuslabels/$statuslabelId/edit")->with('error', Lang::get('admin/statuslabels/message.update.error')); diff --git a/app/database/migrations/2015_02_10_040958_fix_bad_assigned_to_ids.php b/app/database/migrations/2015_02_10_040958_fix_bad_assigned_to_ids.php index b87d5901de..21561894e4 100644 --- a/app/database/migrations/2015_02_10_040958_fix_bad_assigned_to_ids.php +++ b/app/database/migrations/2015_02_10_040958_fix_bad_assigned_to_ids.php @@ -14,7 +14,17 @@ class FixBadAssignedToIds extends Migration { { // DB::statement('update ' . DB::getTablePrefix() . 'assets SET assigned_to=NULL where assigned_to=0'); - DB::statement('update ' . DB::getTablePrefix() . 'licenses SET assigned_to=NULL where assigned_to=0'); + + Schema::table('status_labels', function ($table) { + $table->boolean('deployable')->default(0); + $table->boolean('pending')->default(0); + $table->boolean('archived')->default(0); + $table->text('notes')->nullable(); + }); + + DB::statement('INSERT into ' . DB::getTablePrefix() . 'status_labels (name, deployable, pending, archived, notes) VALUES ("Pending",0,1,0,"These assets are not yet ready to be depoloyed, usually because of configuration or waiting on parts.")'); + DB::statement('INSERT into ' . DB::getTablePrefix() . 'status_labels (name, deployable, pending, archived, notes) VALUES ("Ready to Deploy",1,0,0,"These assets are ready to deploy.")'); + DB::statement('INSERT into ' . DB::getTablePrefix() . 'status_labels (name, deployable, pending, archived, notes) VALUES ("Archived",0,0,1,"These assets are no longer in circulation or viable.")'); } @@ -26,6 +36,13 @@ class FixBadAssignedToIds extends Migration { public function down() { // + Schema::table('status_labels', function ($table) { + $table->dropColumn('deployable'); + $table->dropColumn('pending'); + $table->dropColumn('archived'); + $table->dropColumn('notes'); + + }); } } diff --git a/app/database/migrations/2015_02_10_053310_migrate_data_to_new_statuses.php b/app/database/migrations/2015_02_10_053310_migrate_data_to_new_statuses.php new file mode 100644 index 0000000000..66cb6609df --- /dev/null +++ b/app/database/migrations/2015_02_10_053310_migrate_data_to_new_statuses.php @@ -0,0 +1,60 @@ +name =="Pending") { + $pending_id = array($status->id); + } elseif ($status->name =="Ready to Deploy") { + $rtd_id = array($status->id); + } + } + + // Pending + $pendings = DB::select('select * from ' . DB::getTablePrefix() . 'assets where status_id IS NULL AND physical=1 '); + + foreach ($pendings as $pending) { + DB::update('update ' . DB::getTablePrefix() . 'assets set status_id = ? where status_id IS NULL AND physical=1',$pending_id); + + } + + + // Ready to Deploy + $rtds = DB::select('select * from ' . DB::getTablePrefix() . 'assets where status_id = 0 AND physical=1 '); + + foreach ($rtds as $rtd) { + //DB::update('update users set votes = 100 where name = ?', array('John')); + DB::update('update ' . DB::getTablePrefix() . 'assets set status_id = ? where status_id = 0 AND physical=1',$rtd_id); + + } + + + + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } + +} diff --git a/app/database/seeds/AssetsSeeder.php b/app/database/seeds/AssetsSeeder.php index 693dbfce17..1ce0e24ed8 100755 --- a/app/database/seeds/AssetsSeeder.php +++ b/app/database/seeds/AssetsSeeder.php @@ -25,7 +25,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 0, 'physical' => 1, 'archived' => 0, - 'status_id' => NULL, + 'status_id' => 2, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', @@ -48,7 +48,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 0, 'physical' => 1, 'archived' => 0, - 'status_id' => NULL, + 'status_id' => 1, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', @@ -72,7 +72,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 0, 'physical' => 1, 'archived' => 0, - 'status_id' => 0, + 'status_id' => 2, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', @@ -95,7 +95,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 0, 'physical' => 1, 'archived' => 0, - 'status_id' => 0, + 'status_id' => 1, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', @@ -118,7 +118,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 0, 'physical' => 1, 'archived' => 0, - 'status_id' => 0, + 'status_id' => 2, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', @@ -142,7 +142,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 2, 'physical' => 1, 'archived' => 0, - 'status_id' => 0, + 'status_id' => 1, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', @@ -165,7 +165,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 2, 'physical' => 1, 'archived' => 0, - 'status_id' => 0, + 'status_id' => 1, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', @@ -280,7 +280,7 @@ class AssetsSeeder extends Seeder 'assigned_to' => 0, 'physical' => 1, 'archived' => 0, - 'status_id' => 0, + 'status_id' => 1, 'notes' => '', 'deleted_at' => NULL, 'archived' => '0', diff --git a/app/database/seeds/StatuslabelsSeeder.php b/app/database/seeds/StatuslabelsSeeder.php index abedf39a30..6531b778dc 100755 --- a/app/database/seeds/StatuslabelsSeeder.php +++ b/app/database/seeds/StatuslabelsSeeder.php @@ -10,12 +10,41 @@ class StatuslabelsSeeder extends Seeder $date = new DateTime; + $status[] = array( + 'name' => 'Ready to Deploy', + 'created_at' => $date->modify('-10 day'), + 'updated_at' => $date->modify('-3 day'), + 'user_id' => 1, + 'deleted_at' => NULL, + 'deployable' => 1, + 'pending' => 0, + 'archived' => 0, + 'notes' => '' + ); + + $status[] = array( + 'name' => 'Pending', + 'created_at' => $date->modify('-10 day'), + 'updated_at' => $date->modify('-3 day'), + 'user_id' => 1, + 'deleted_at' => NULL, + 'deployable' => 0, + 'pending' => 1, + 'archived' => 0, + 'notes' => '' + ); + + $status[] = array( 'name' => 'Out for Diagnostics', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, 'deleted_at' => NULL, + 'deployable' => 0, + 'pending' => 0, + 'archived' => 0, + 'notes' => '' ); @@ -25,6 +54,10 @@ class StatuslabelsSeeder extends Seeder 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, 'deleted_at' => NULL, + 'deployable' => 0, + 'pending' => 0, + 'archived' => 0, + 'notes' => '' ); @@ -34,6 +67,10 @@ class StatuslabelsSeeder extends Seeder 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, 'deleted_at' => NULL, + 'deployable' => 0, + 'pending' => 0, + 'archived' => 1, + 'notes' => '' ); $status[] = array( @@ -42,6 +79,10 @@ class StatuslabelsSeeder extends Seeder 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, 'deleted_at' => NULL, + 'deployable' => 0, + 'pending' => 0, + 'archived' => 1, + 'notes' => '', ); diff --git a/app/lang/en/admin/hardware/form.php b/app/lang/en/admin/hardware/form.php index 6b6b6e512d..aef375bd0a 100755 --- a/app/lang/en/admin/hardware/form.php +++ b/app/lang/en/admin/hardware/form.php @@ -23,6 +23,7 @@ return array( 'order' => 'Order Number', 'qr' => 'QR Code', 'requestable' => 'Users may request this asset', + 'select_statustype' => 'Select Status Type', 'serial' => 'Serial', 'status' => 'Status', 'supplier' => 'Supplier', diff --git a/app/lang/en/admin/hardware/general.php b/app/lang/en/admin/hardware/general.php index 9e7915462f..a89940af34 100755 --- a/app/lang/en/admin/hardware/general.php +++ b/app/lang/en/admin/hardware/general.php @@ -1,11 +1,14 @@ 'Archived', 'asset' => 'Asset', 'checkin' => 'Checkin Asset', 'checkout' => 'Checkout Asset to User', 'clone' => 'Clone Asset', + 'deployable' => 'Deployable', 'edit' => 'Edit Asset', - 'pending' => 'Pending Asset', + 'pending' => 'Pending', + 'undeployable' => 'Undeployable', 'view' => 'View Asset', ); diff --git a/app/lang/en/admin/statuslabels/table.php b/app/lang/en/admin/statuslabels/table.php index 54094c5491..dd21781115 100755 --- a/app/lang/en/admin/statuslabels/table.php +++ b/app/lang/en/admin/statuslabels/table.php @@ -1,10 +1,15 @@ 'Status Name', - 'title' => 'Status Labels', - 'update' => 'Update Status Label', - 'create' => 'Create Status Label', 'about' => 'About Status Labels', - 'info' => 'Status labels are used to describe the various reasons why an asset cannot be deployed. It could be broken, out for diagnostics, out for repair, lost or stolen, etc. Status labels allow your team to show the progression.', + 'archived' => 'Archived', + 'create' => 'Create Status Label', + 'deployable' => 'Deployable', + 'info' => 'Status labels are used to describe the various states your assets could be in. They may be out for repair, lost/stolen, etc. You can create new status labels for deployable, pending and archived assets.', + 'name' => 'Status Name', + 'pending' => 'Pending', + 'status_type' => 'Status Type', + 'title' => 'Status Labels', + 'undeployable' => 'Undeployable', + 'update' => 'Update Status Label', ); diff --git a/app/models/Asset.php b/app/models/Asset.php index 2e5b1ff1db..34e232e960 100755 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -231,7 +231,10 @@ class Asset extends Elegant public function scopePending($query) { - return $query->whereNull('status_id','and')->where('assigned_to','=','0'); + return $query->whereHas('assetstatus',function($query) + { + $query->where('pending','=',1); + }); } @@ -244,10 +247,15 @@ class Asset extends Elegant public function scopeRTD($query) { - return $query->where('status_id','=','0')->whereNull('assigned_to'); + return $query->whereHas('assetstatus',function($query) + { + $query->where('deployable','=',1); + }); } + + /** * Query builder scope for Undeployable assets * @@ -257,7 +265,10 @@ class Asset extends Elegant public function scopeUndeployable($query) { - return $query->where('status_id','>',1)->where('assigned_to','=','0'); + return $query->whereHas('assetstatus',function($query) + { + $query->where('deployable','=',0); + }); } diff --git a/app/models/Statuslabel.php b/app/models/Statuslabel.php index 38c31f6bf9..35919be758 100755 --- a/app/models/Statuslabel.php +++ b/app/models/Statuslabel.php @@ -9,10 +9,49 @@ class Statuslabel extends Elegant protected $rules = array( 'name' => 'required|alpha_space|min:2|max:100|unique:status_labels,name,{id}', + 'statuslabel_types' => 'required|in:deployable,pending,archived', ); public function has_assets() { return $this->hasMany('Asset', 'status_id')->count(); } + + public function getStatuslabelType() { + + if ($this->pending == 1) { + return 'pending'; + } elseif ($this->archived == 1) { + return 'archived'; + } elseif (($this->archived == 0) && ($this->deployable == 0) && ($this->deployable == 0)) { + return 'undeployable'; + } else { + return 'deployable'; + } + } + + public static function getStatuslabelTypesForDB($type) { + if ($type == 'pending') { + $statustype['pending'] = 1; + $statustype['deployable'] = 0; + $statustype['archived'] = 0; + + } elseif ($type == 'deployable') { + $statustype['pending'] = 0; + $statustype['deployable'] = 1; + $statustype['archived'] = 0; + + } elseif ($type == 'archived') { + $statustype['pending'] = 0; + $statustype['deployable'] = 0; + $statustype['archived'] = 1; + + } elseif ($type == 'undeployable') { + $statustype['pending'] = 0; + $statustype['deployable'] = 0; + $statustype['archived'] = 0; + } + + return $statustype; + } } diff --git a/app/views/backend/hardware/edit.blade.php b/app/views/backend/hardware/edit.blade.php index 2f605ec4e5..30a99586ab 100755 --- a/app/views/backend/hardware/edit.blade.php +++ b/app/views/backend/hardware/edit.blade.php @@ -82,6 +82,7 @@
@if (isset($selected_model)) {{ Form::select('model_id', $model_list , $selected_model->id, array('class'=>'select2', 'style'=>'min-width:400px')) }} + @else {{ Form::select('model_id', $model_list , Input::old('model_id', $asset->model_id), array('class'=>'select2', 'style'=>'min-width:400px')) }} @endif diff --git a/app/views/backend/hardware/view.blade.php b/app/views/backend/hardware/view.blade.php index b234c99d3e..ba6f027e93 100755 --- a/app/views/backend/hardware/view.blade.php +++ b/app/views/backend/hardware/view.blade.php @@ -283,37 +283,27 @@

  • @lang('admin/hardware/general.checkin')
  • + @endif - @elseif (($asset->status_id ) && ($asset->status_id > 1)) - + @if (($asset->status_id ) && ($asset->status_id > 1)) + @if ($asset->assetstatus)

    {{{ $asset->assetstatus->name }}} @lang('admin/hardware/general.asset')
    + @if ($asset->assetstatus->notes)
    -
    - - @lang('admin/hardware/message.undeployable') +
    + + {{{ $asset->assetstatus->notes }}}
    + @endif
    - @endif - - - @elseif ($asset->status_id == NULL) - -

    @lang('admin/hardware/general.pending')
    - - - @elseif ($asset->status_id == 0) - -

    @lang('admin/hardware/general.checkout')
    - + @endif @endif +
    diff --git a/app/views/backend/reports/asset.blade.php b/app/views/backend/reports/asset.blade.php index e1a5b8fbef..197d43e363 100644 --- a/app/views/backend/reports/asset.blade.php +++ b/app/views/backend/reports/asset.blade.php @@ -34,6 +34,7 @@ @lang('general.name') @endif @lang('admin/hardware/table.serial') + @lang('admin/hardware/table.status') @lang('admin/hardware/table.purchase_date') @lang('admin/hardware/table.purchase_cost') @lang('admin/hardware/form.order') @@ -54,11 +55,19 @@ @endif {{{ $asset->model->name }}} - {{{ $asset->model->modelno }}} + {{{ $asset->model->modelno }}} @if (Setting::getSettings()->display_asset_name) {{{ $asset->name }}} @endif {{ $asset->serial }} + + + @if ($asset->assetstatus) + {{{ $asset->assetstatus->name }}} + @elseif ($asset->assigneduser) + {{{ $asset->assigneduser->fullName() }}} + @endif + {{{ $asset->purchase_date }}} @lang('general.currency') {{{ number_format($asset->purchase_cost) }}} diff --git a/app/views/backend/statuslabels/edit.blade.php b/app/views/backend/statuslabels/edit.blade.php index 957c8d174f..14072b00e7 100755 --- a/app/views/backend/statuslabels/edit.blade.php +++ b/app/views/backend/statuslabels/edit.blade.php @@ -50,6 +50,32 @@ + + +
    + +
    + + {{ $errors->first('notes', ' :message') }} +
    +
    + + + +
    + + +
    + {{ Form::select('statuslabel_types', $statuslabel_types , $use_statuslabel_type, array('class'=>'select2', 'style'=>'min-width:400px')) }} + {{ $errors->first('notes', ' :message') }} + {{ $errors->first('status_type', ' :message') }} +
    +
    + + + +
    diff --git a/app/views/backend/statuslabels/index.blade.php b/app/views/backend/statuslabels/index.blade.php index e31cf43ef3..f211d25b3d 100755 --- a/app/views/backend/statuslabels/index.blade.php +++ b/app/views/backend/statuslabels/index.blade.php @@ -28,6 +28,7 @@ @lang('admin/statuslabels/table.name') + @lang('admin/statuslabels/table.status_type') @lang('table.actions') @@ -35,6 +36,17 @@ @foreach ($statuslabels as $statuslabel) {{{ $statuslabel->name }}} + + @if ($statuslabel->deployable == 1) + @lang('admin/statuslabels/table.deployable') + @elseif ($statuslabel->pending == 1) + @lang('admin/statuslabels/table.pending') + @elseif ($statuslabel->archived == 1) + @lang('admin/statuslabels/table.archived') + @else + @lang('admin/statuslabels/table.undeployable') + @endif +