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
+
+
+
+
| @lang('general.name') | +@lang('table.actions') | +
|---|---|
| {{{ $seat->license->name }}} | +@lang('general.checkin') + | +
+ @lang('admin/licenses/form.checkout_help') +
+