diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index 704b09d7a0..94cdbab32d 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -1,5 +1,6 @@ 'Top Level') + License::lists('name', 'id'); + // Show the page $depreciation_list = array('0' => Lang::get('admin/licenses/form.no_depreciation')) + Depreciation::lists('name', 'id'); return View::make('backend/licenses/edit')->with('license_options',$license_options)->with('depreciation_list',$depreciation_list)->with('license',new License); @@ -79,6 +82,7 @@ class LicensesController extends AdminController $license->purchase_date = e(Input::get('purchase_date')); $license->purchase_cost = e(Input::get('purchase_cost')); $license->depreciation_id = e(Input::get('depreciation_id')); + $license->asset_id = e(Input::get('asset_id')); $license->user_id = Sentry::getId(); if (($license->purchase_date == "") || ($license->purchase_date == "0000-00-00")) { @@ -177,6 +181,7 @@ class LicensesController extends AdminController $license->notes = e(Input::get('notes')); $license->order_number = e(Input::get('order_number')); $license->depreciation_id = e(Input::get('depreciation_id')); + $license->asset_id = e(Input::get('asset_id')); // Update the asset data if ( e(Input::get('purchase_date')) == '') { @@ -312,8 +317,10 @@ class LicensesController extends AdminController // Get the dropdown of users and then pass it to the checkout view $users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat (first_name," ",last_name) as full_name, id'))->whereNull('deleted_at')->lists('full_name', 'id'); + $asset_list = array('' => '') + Asset::orderBy('name', 'asc')->lists('name', 'id'); + //print_r($users); - return View::make('backend/licenses/checkout', compact('licenseseat'))->with('users_list',$users_list); + return View::make('backend/licenses/checkout', compact('licenseseat'))->with('users_list',$users_list)->with('asset_list',$asset_list); } @@ -331,11 +338,13 @@ class LicensesController extends AdminController } $assigned_to = e(Input::get('assigned_to')); + $asset_id = e(Input::get('asset_id')); // Declare the rules for the form validation $rules = array( - 'assigned_to' => 'required|integer|min:1', + 'note' => 'alpha_space', + 'asset_id' => 'required_without:assigned_to', ); // Create a new validator instance from our validation rules @@ -347,17 +356,38 @@ class LicensesController extends AdminController return Redirect::back()->withInput()->withErrors($validator); } - + if ($assigned_to!='') { // Check if the user exists - if (is_null($assigned_to = User::find($assigned_to))) { - // Redirect to the asset management page with error - return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.user_does_not_exist')); + if (is_null($is_assigned_to = User::find($assigned_to))) { + // Redirect to the asset management page with error + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.user_does_not_exist')); + } } + if ($asset_id!='') { + + if (is_null($is_asset_id = Asset::find($asset_id))) { + // Redirect to the asset management page with error + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.asset_does_not_exist')); + } + + if (($is_asset_id->assigned_to!=$assigned_to) && ($assigned_to!='')) { + //echo 'asset assigned to: '.$is_asset_id->assigned_to.'
license assigned to: '.$assigned_to; + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.owner_doesnt_match_asset')); + } + + } + + + + + + $licenseseat->asset_id = e(Input::get('asset_id')); // Update the asset data if ( e(Input::get('assigned_to')) == '') { $licenseseat->assigned_to = NULL; + } else { $licenseseat->assigned_to = e(Input::get('assigned_to')); } @@ -366,8 +396,8 @@ class LicensesController extends AdminController if($licenseseat->save()) { $logaction = new Actionlog(); - $logaction->asset_id = $licenseseat->license_id; - $logaction->location_id = $assigned_to->location_id; + + //$logaction->location_id = $assigned_to->location_id; $logaction->asset_type = 'software'; $logaction->user_id = Sentry::getUser()->id; $logaction->note = e(Input::get('note')); @@ -439,10 +469,11 @@ class LicensesController extends AdminController // Update the asset data $licenseseat->assigned_to = '0'; + $licenseseat->asset_id = NULL; // Was the asset updated? if($licenseseat->save()) { - $logaction->asset_id = $licenseseat->license_id; + $logaction->asset_id = NULL; $logaction->location_id = NULL; $logaction->asset_type = 'software'; $logaction->note = e(Input::get('note')); diff --git a/app/database/migrations/2014_07_17_085822_add_asset_to_software.php b/app/database/migrations/2014_07_17_085822_add_asset_to_software.php new file mode 100644 index 0000000000..ecca3f4387 --- /dev/null +++ b/app/database/migrations/2014_07_17_085822_add_asset_to_software.php @@ -0,0 +1,34 @@ +integer('asset_id')->nullable()->default(NULL); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + Schema::table('license_seats', function ($table) { + $table->dropColumn('asset_id'); + }); + } + +} diff --git a/app/database/migrations/2014_07_17_161625_make_asset_id_in_logs_nullable.php b/app/database/migrations/2014_07_17_161625_make_asset_id_in_logs_nullable.php new file mode 100644 index 0000000000..668c4432c7 --- /dev/null +++ b/app/database/migrations/2014_07_17_161625_make_asset_id_in_logs_nullable.php @@ -0,0 +1,29 @@ + '1', 'assigned_to' => '1', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), + 'created_at' => $date->modify('-10 day')->format('Y-m-d H:i:s'), + 'updated_at' => $date->modify('-3 day')->format('Y-m-d H:i:s'), 'deleted_at' => NULL, 'notes' => '', 'user_id' => '1', - ); - - $license_seats[] = array( - 'license_id' => '1', - 'assigned_to' => '0', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), - 'deleted_at' => NULL, - 'notes' => '', - 'user_id' => '1', - ); - - $license_seats[] = array( - 'license_id' => '1', - 'assigned_to' => '0', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), - 'deleted_at' => NULL, - 'notes' => '', - 'user_id' => '1', - ); - - $license_seats[] = array( - 'license_id' => '1', - 'assigned_to' => '0', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), - 'deleted_at' => NULL, - 'notes' => '', - 'user_id' => '1', + 'asset_id' => '1', ); $license_seats[] = array( 'license_id' => '1', 'assigned_to' => '2', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), + 'created_at' => $date->modify('-10 day')->format('Y-m-d H:i:s'), + 'updated_at' => $date->modify('-3 day')->format('Y-m-d H:i:s'), 'deleted_at' => NULL, 'notes' => '', 'user_id' => '1', + 'asset_id' => '2', + ); + + $license_seats[] = array( + 'license_id' => '1', + 'assigned_to' => '3', + 'created_at' => $date->modify('-10 day')->format('Y-m-d H:i:s'), + 'updated_at' => $date->modify('-3 day')->format('Y-m-d H:i:s'), + 'deleted_at' => NULL, + 'notes' => '', + 'user_id' => '1', + 'asset_id' => '3', + ); + + $license_seats[] = array( + 'license_id' => '1', + 'assigned_to' => '0', + 'created_at' => $date->modify('-10 day')->format('Y-m-d H:i:s'), + 'updated_at' => $date->modify('-3 day')->format('Y-m-d H:i:s'), + 'deleted_at' => NULL, + 'notes' => '', + 'user_id' => '1', + 'asset_id' => NULL, + ); + + $license_seats[] = array( + 'license_id' => '1', + 'assigned_to' => '2', + 'created_at' => $date->modify('-10 day')->format('Y-m-d H:i:s'), + 'updated_at' => $date->modify('-3 day')->format('Y-m-d H:i:s'), + 'deleted_at' => NULL, + 'notes' => '', + 'user_id' => '1', + 'asset_id' => NULL, ); $license_seats[] = array( 'license_id' => '2', 'assigned_to' => '1', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), + 'created_at' => $date->modify('-10 day')->format('Y-m-d H:i:s'), + 'updated_at' => $date->modify('-3 day')->format('Y-m-d H:i:s'), 'deleted_at' => NULL, 'notes' => '', 'user_id' => '1', + 'asset_id' => NULL, ); // Pending (status_id is null, assigned_to = 0) $license_seats[] = array( 'license_id' => '2', 'assigned_to' => '0', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), + 'created_at' => $date->modify('-10 day')->format('Y-m-d H:i:s'), + 'updated_at' => $date->modify('-3 day')->format('Y-m-d H:i:s'), 'deleted_at' => NULL, 'notes' => '', 'user_id' => '1', + 'asset_id' => NULL, ); diff --git a/app/lang/en/admin/licenses/form.php b/app/lang/en/admin/licenses/form.php index 77ecae052f..b0bcc96ac2 100644 --- a/app/lang/en/admin/licenses/form.php +++ b/app/lang/en/admin/licenses/form.php @@ -2,6 +2,7 @@ return array( + 'asset' => 'Asset', 'checkin' => 'Checkin', 'checkin' => 'Checkin', 'cost' => 'Purchase Cost', @@ -19,5 +20,5 @@ return array( 'to_email' => 'Licensed to Email', 'to_name' => 'Licensed to Name', 'update' => 'Update License', - + 'checkout_help' => 'You must check a license out to a hardware asset or a person. You can select both, but the owner of the asset must match the person you\'re checking the asset out to.' ); diff --git a/app/lang/en/admin/licenses/general.php b/app/lang/en/admin/licenses/general.php index 1e95035d80..bd38945704 100644 --- a/app/lang/en/admin/licenses/general.php +++ b/app/lang/en/admin/licenses/general.php @@ -4,7 +4,7 @@ return array( 'checkin' => 'Checkin License Seat', 'checkout_history' => 'Checkout History', - 'checkout' => 'Checkout License Seat to User', + 'checkout' => 'Checkout License Seat', 'edit' => 'Edit License', 'history_for' => 'History for ', 'in_out' => 'In/Out', diff --git a/app/lang/en/admin/licenses/message.php b/app/lang/en/admin/licenses/message.php index 3ac4869cfe..cc37033927 100755 --- a/app/lang/en/admin/licenses/message.php +++ b/app/lang/en/admin/licenses/message.php @@ -4,6 +4,7 @@ return array( 'does_not_exist' => 'License does not exist.', 'user_does_not_exist' => 'User does not exist.', + 'owner_doesnt_match_asset' => 'The asset you are trying to associate with this license is owned by somene other than the person selected in the assigned to dropdown.', 'assoc_users' => 'This license is currently checked out to a user and cannot be deleted. Please check the license in first, and then try deleting again. ', diff --git a/app/lang/en/admin/licenses/table.php b/app/lang/en/admin/licenses/table.php index dec01efd26..dfce4136cb 100755 --- a/app/lang/en/admin/licenses/table.php +++ b/app/lang/en/admin/licenses/table.php @@ -10,6 +10,7 @@ return array( 'purchase_date' => 'Purchase Date', 'purchased' => 'Purchased', 'seats' => 'Seats', + 'hardware' => 'Hardware', 'serial' => 'Serial', 'title' => 'License', diff --git a/app/lang/en/general.php b/app/lang/en/general.php index 7133273214..0a0dbabb74 100755 --- a/app/lang/en/general.php +++ b/app/lang/en/general.php @@ -53,6 +53,7 @@ return array( 'no_depreciation' => 'No Derepciation', 'no_results' => 'No Results.', 'no' => 'No', + 'notes' => 'Notes', 'pending' => 'Pending', 'people' => 'People', 'per_page' => 'Results Per Page', diff --git a/app/models/Asset.php b/app/models/Asset.php index 8d2a67cb92..d21da3cfeb 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -149,6 +149,21 @@ class Asset extends Elegant return $this->belongsTo('Model','model_id'); } + /** + * Get the license seat information + **/ + public function licenses() + { + return $this->belongsToMany('License', 'license_seats', 'asset_id', 'license_id'); + + } + + public function licenseseats() + { + return $this->hasMany('LicenseSeat', 'asset_id'); + } + + public function supplier() { return $this->belongsTo('Supplier','supplier_id'); diff --git a/app/models/License.php b/app/models/License.php index b457ad6e86..b6e5e10a47 100644 --- a/app/models/License.php +++ b/app/models/License.php @@ -24,7 +24,6 @@ class License extends Elegant } - /** * Get asset logs for this asset */ diff --git a/app/models/LicenseSeat.php b/app/models/LicenseSeat.php index f4d3b44e4a..4fab293817 100644 --- a/app/models/LicenseSeat.php +++ b/app/models/LicenseSeat.php @@ -2,6 +2,7 @@ class LicenseSeat extends Elegant { + protected $guarded = 'id'; protected $table = 'license_seats'; protected $softDelete = true; @@ -15,4 +16,9 @@ class LicenseSeat extends Elegant return $this->belongsTo('User','assigned_to')->withTrashed(); } + public function asset() + { + return $this->belongsTo('Asset','asset_id')->withTrashed(); + } + } diff --git a/app/views/backend/hardware/view.blade.php b/app/views/backend/hardware/view.blade.php index 2b1f311567..16b9900186 100644 --- a/app/views/backend/hardware/view.blade.php +++ b/app/views/backend/hardware/view.blade.php @@ -128,8 +128,41 @@ @endif + + + +
Software Assigned to {{{ $asset->name }}}
+
+ + @if (count($asset->licenses) > 0) + + + + + + + + + @foreach ($asset->licenseseats as $seat) + + + + + @endforeach + +
@lang('general.name')@lang('table.actions')
{{{ $seat->license->name }}}@lang('general.checkin') +
+ @else + +
+
+ + @lang('general.no_results') +
+
+ @endif @@ -137,11 +170,11 @@ - Date - Admin - Action - User - Note + @lang('general.date') + @lang('general.admin') + @lang('table.action') + @lang('general.user') + @lang('general.notes') diff --git a/app/views/backend/licenses/checkout.blade.php b/app/views/backend/licenses/checkout.blade.php index 111d7c8ae9..64ea0162fc 100644 --- a/app/views/backend/licenses/checkout.blade.php +++ b/app/views/backend/licenses/checkout.blade.php @@ -43,17 +43,36 @@ + +
+ + +
+ {{ Form::select('asset_id', $asset_list , Input::old('asset_id', $licenseseat->asset_id), array('class'=>'select2', 'style'=>'min-width:350px')) }} + {{ $errors->first('asset_id', ' :message') }} +
+
+ +
- -
+ + +
{{ Form::select('assigned_to', $users_list , Input::old('assigned_to', $licenseseat->assigned_to), array('class'=>'select2', 'style'=>'min-width:350px')) }} {{ $errors->first('assigned_to', ' :message') }} + +

+ @lang('admin/licenses/form.checkout_help') +

+
+
diff --git a/app/views/backend/licenses/index.blade.php b/app/views/backend/licenses/index.blade.php index fa8df27692..82f675908c 100755 --- a/app/views/backend/licenses/index.blade.php +++ b/app/views/backend/licenses/index.blade.php @@ -23,6 +23,7 @@ @lang('admin/licenses/table.title') @lang('admin/licenses/table.serial') + @lang('admin/licenses/table.hardware') @lang('admin/licenses/table.assigned_to') @lang('admin/licenses/general.in_out') @lang('table.actions') @@ -44,6 +45,13 @@ {{ Str::limit($license->serial, 40); }} + + @if ($licensedto->asset_id) + + {{ $licensedto->asset->name }} + + @endif + @if (($licensedto->assigned_to) && ($licensedto->deleted_at == NULL)) @@ -52,9 +60,11 @@ @elseif (($licensedto->assigned_to) && ($licensedto->deleted_at != NULL)) {{ $licensedto->user->fullName() }} @endif + + - @if ($licensedto->assigned_to) + @if (($licensedto->assigned_to) || ($licensedto->asset_id)) @lang('general.checkin') @else diff --git a/app/views/backend/licenses/view.blade.php b/app/views/backend/licenses/view.blade.php index 2097eb2500..8996f9f8af 100644 --- a/app/views/backend/licenses/view.blade.php +++ b/app/views/backend/licenses/view.blade.php @@ -69,7 +69,8 @@ @lang('admin/licenses/general.seat') - @lang('admin/licenses/general.user') + @lang('admin/licenses/general.user') + @lang('admin/licenses/form.asset') @@ -88,6 +89,13 @@ @endif + @if ($licensedto->asset_id) + + {{ $licensedto->asset->name }} {{ $licensedto->asset->asset_tag }} + + @endif + + @if ($licensedto->assigned_to) @lang('general.checkin') @else