A free open source IT asset/license management system
Fix 2347 (#2394)
Daniel Meltzera852c624d3c3
diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.phpindex 336c6d8232..0358040d68 100755--- a/app/Http/Controllers/AssetsController.php+++ b/app/Http/Controllers/AssetsController.php@@ -530,6 +530,8 @@ class AssetsController extends Controllerreturn redirect()->to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));} elseif (!Company::isCurrentUserHasAccess($asset)) {return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));+ } elseif (!$asset->availableForCheckout()) {+ return redirect()->to('hardware')->with('error', trans('admin/hardware/message.checkout.not_available'));}$user = User::find(e(Input::get('assigned_to')));@@ -1725,19 +1727,17 @@ class AssetsController extends Controller$actions = '<a href="'.route('restore/hardware', $asset->id).'" title="Restore asset" data-toggle="tooltip" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';}- if ($asset->assetstatus) {- if (($asset->assetstatus->deployable != 0) && ($asset->deleted_at=='')) {- if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) {- if (Gate::allows('assets.checkin')) {- $inout = '<a href="' . route('checkin/hardware',- $asset->id) . '" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">' . trans('general.checkin') . '</a>';- }- } else {- if (Gate::allows('assets.checkout')) {- $inout = '<a href="' . route('checkout/hardware',- $asset->id) . '" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">' . trans('general.checkout') . '</a>';- }- }+ if (($asset->availableForCheckout()))+ {+ if (Gate::allows('assets.checkout')) {+ $inout = '<a href="' . route('checkout/hardware',+ $asset->id) . '" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">' . trans('general.checkout') . '</a>';+ }++ } else {+ if (Gate::allows('assets.checkin')) {+ $inout = '<a href="' . route('checkin/hardware',+ $asset->id) . '" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">' . trans('general.checkin') . '</a>';}}diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.phpindex 005cc09b22..f6141c8e05 100755--- a/app/Http/Controllers/CategoriesController.php+++ b/app/Http/Controllers/CategoriesController.php@@ -1,13 +1,14 @@<?phpnamespace App\Http\Controllers;-use Illuminate\Http\Request;use App\Helpers\Helper;use App\Models\Category as Category;use App\Models\Company;use App\Models\Setting;use Auth;use DB;+use Illuminate\Http\Request;+use Illuminate\Support\Facades\Gate;use Input;use Lang;use Redirect;@@ -344,13 +345,13 @@ class CategoriesController extends Controller$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';}- if ($asset->assetstatus) {- if ($asset->assetstatus->deployable != 0) {- if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) {- $inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';- } else {- $inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';- }+ if ($asset->availableForCheckout()) {+ if (Gate::allows('assets.checkout')) {+ $inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';+ }+ } else {+ if (Gate::allows('assets.checkin')) {+ $inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';}}diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.phpindex 7f0bb51dff..312083bc5a 100755--- a/app/Http/Controllers/ManufacturersController.php+++ b/app/Http/Controllers/ManufacturersController.php@@ -2,14 +2,15 @@namespace App\Http\Controllers;use App\Models\Company;+use App\Models\Manufacturer;+use App\Models\Setting;+use Auth;+use Illuminate\Support\Facades\Gate;use Input;use Lang;-use App\Models\Manufacturer;use Redirect;-use App\Models\Setting;use Str;use View;-use Auth;/*** This controller handles all actions related to Manufacturers for@@ -293,13 +294,13 @@ class ManufacturersController extends Controller$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';}- if ($asset->assetstatus) {- if ($asset->assetstatus->deployable != 0) {- if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) {- $inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';- } else {- $inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';- }+ if ($asset->availableForCheckout()) {+ if (Gate::allows('assets.checkout')) {+ $inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';+ }+ } else {+ if (Gate::allows('assets.checkin')) {+ $inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';}}diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex 3531b55043..24fcd443f6 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -72,16 +72,26 @@ class Asset extends Depreciable}-+ public function availableForCheckout()+ {+ return (+ empty($this->assigned_to) &&+ $this->assetstatus->deployable == 1 &&+ empty($this->deleted_at)+ );+ }/*** Checkout asset*/public function checkOutToUser($user, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null){+ if (!$user) {+ return false;+ }if ($expected_checkin) {- $this->expected_checkin = $expected_checkin ;+ $this->expected_checkin = $expected_checkin;}$this->last_checkout = $checkout_at;@@ -95,9 +105,7 @@ class Asset extends Depreciable$this->accepted="pending";}- if (!$user) {- return false;- }+if ($this->save()) {diff --git a/resources/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.phpindex dd23fe7474..26a5eec28f 100644--- a/resources/lang/en/admin/hardware/message.php+++ b/resources/lang/en/admin/hardware/message.php@@ -52,7 +52,8 @@ return array('checkout' => array('error' => 'Asset was not checked out, please try again','success' => 'Asset checked out successfully.',- 'user_does_not_exist' => 'That user is invalid. Please try again.'+ 'user_does_not_exist' => 'That user is invalid. Please try again.',+ 'not_available' => 'That asset is not available for checkout!'),'checkin' => array(