diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.php index a34de73d77..257722b005 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckinController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php @@ -61,7 +61,7 @@ class LicenseCheckinController extends Controller $license = License::find($licenseSeat->license_id); // LicenseSeat is not assigned, it can't be checked in - if (is_null($licenseSeat->assignedTo) && is_null($licenseSeat->asset_id)) { + if (is_null($licenseSeat->assigned_to) && is_null($licenseSeat->asset_id)) { return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkin.error')); } diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 9524abf6ee..39b73a9797 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -227,6 +227,36 @@ class LocationsController extends Controller } + + /** + * Returns a view that presents a form to clone a location. + * + * @author [A. Gianotto] [] + * @param int $locationId + * @since [v6.0.14] + * @return View + */ + public function getClone($locationId = null) + { + $this->authorize('create', Location::class); + + // Check if the asset exists + if (is_null($location_to_clone = Location::find($locationId))) { + // Redirect to the asset management page + return redirect()->route('licenses.index')->with('error', trans('admin/locations/message.does_not_exist')); + } + + $location = clone $location_to_clone; + + // unset these values + $location->id = null; + $location->image = null; + + return view('locations/edit') + ->with('item', $location); + } + + public function print_all_assigned($id) { if ($location = Location::where('id', $id)->first()) { diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index a55c41b350..22eade5d6e 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -4,7 +4,7 @@ namespace App\Http\Transformers; use App\Helpers\Helper; use App\Models\Location; -use Gate; +use Illuminate\Support\Facades\Gate; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\Storage; @@ -63,6 +63,7 @@ class LocationsTransformer $permissions_array['available_actions'] = [ 'update' => Gate::allows('update', Location::class) ? true : false, 'delete' => $location->isDeletable(), + 'clone' => (Gate::allows('create', Location::class) && ($location->deleted_at == '')), ]; $array += $permissions_array; diff --git a/resources/views/groups/index.blade.php b/resources/views/groups/index.blade.php index ffc193c7cf..4958e3a4d0 100755 --- a/resources/views/groups/index.blade.php +++ b/resources/views/groups/index.blade.php @@ -41,7 +41,7 @@ - {{ trans('general.id') }} + {{ trans('general.id') }} {{ trans('admin/groups/table.name') }} {{ trans('admin/groups/table.users') }} {{ trans('general.created_at') }} diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.php index 0c93c83a81..10d0f59bb0 100755 --- a/resources/views/locations/edit.blade.php +++ b/resources/views/locations/edit.blade.php @@ -65,50 +65,3 @@ @include ('partials.forms.edit.image-upload') @stop -@if (!$item->id) -@section('moar_scripts') - -@stop -@endif diff --git a/routes/web.php b/routes/web.php index 4c52918f8e..cc358c910f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -40,22 +40,36 @@ Route::group(['middleware' => 'auth'], function () { 'parameters' => ['category' => 'category_id'], ]); + + /* - * Locations - */ + * Locations + */ + + Route::group(['prefix' => 'locations', 'middleware' => ['auth']], function () { + + Route::get('{locationId}/clone', + [LocationsController::class, 'getClone'] + )->name('clone/license'); + + Route::get( + '{locationId}/printassigned', + [LocationsController::class, 'print_assigned'] + )->name('locations.print_assigned'); + + Route::get( + '{locationId}/printallassigned', + [LocationsController::class, 'print_all_assigned'] + )->name('locations.print_all_assigned'); + }); + Route::resource('locations', LocationsController::class, [ 'parameters' => ['location' => 'location_id'], ]); - Route::get( - 'locations/{locationId}/printassigned', - [LocationsController::class, 'print_assigned'] - )->name('locations.print_assigned'); - Route::get( - 'locations/{locationId}/printallassigned', - [LocationsController::class, 'print_all_assigned'] - )->name('locations.print_all_assigned'); + + /* * Manufacturers