diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index 8fd78f33ea..c011968591 100755 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -15,6 +15,7 @@ use Depreciation; use Setting; use Sentry; use Str; +use Supplier; use Validator; use View; @@ -49,10 +50,10 @@ class LicensesController extends AdminController { // Show the page $license_options = array('0' => '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); + $supplier_list = array('' => 'Select Supplier') + Supplier::orderBy('name', 'asc')->lists('name', 'id'); + return View::make('backend/licenses/edit')->with('license_options',$license_options)->with('depreciation_list',$depreciation_list)->with('supplier_list',$supplier_list)->with('license',new License); } @@ -74,31 +75,43 @@ class LicensesController extends AdminController // attempt validation if ($license->validate($new)) { - if ( e(Input::get('purchase_cost')) == '') { + if ( e(Input::get('purchase_cost')) == '') { $license->purchase_cost = NULL; } else { $license->purchase_cost = ParseFloat(e(Input::get('purchase_cost'))); //$license->purchase_cost = e(Input::get('purchase_cost')); } + if ( e(Input::get('supplier_id')) == '') { + $license->supplier_id = NULL; + } else { + $license->supplier_id = e(Input::get('supplier_id')); + } + // Save the license data - $license->name = e(Input::get('name')); - $license->serial = e(Input::get('serial')); - $license->license_email = e(Input::get('license_email')); - $license->license_name = e(Input::get('license_name')); - $license->notes = e(Input::get('notes')); - $license->order_number = e(Input::get('order_number')); - $license->seats = e(Input::get('seats')); - $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(); + $license->name = e(Input::get('name')); + $license->serial = e(Input::get('serial')); + $license->license_email = e(Input::get('license_email')); + $license->license_name = e(Input::get('license_name')); + $license->notes = e(Input::get('notes')); + $license->order_number = e(Input::get('order_number')); + $license->seats = e(Input::get('seats')); + $license->purchase_date = e(Input::get('purchase_date')); + $license->purchase_order = e(Input::get('purchase_order')); + //$license->purchase_cost = e(Input::get('purchase_cost')); + $license->depreciation_id = e(Input::get('depreciation_id')); + $license->expiration_date = e(Input::get('expiration_date')); + //$license->asset_id = e(Input::get('asset_id')); + $license->user_id = Sentry::getId(); if (($license->purchase_date == "") || ($license->purchase_date == "0000-00-00")) { $license->purchase_date = NULL; } + if (($license->expiration_date == "") || ($license->expiration_date == "0000-00-00")) { + $license->expiration_date = NULL; + } + if (($license->purchase_cost == "") || ($license->purchase_cost == "0.00")) { $license->purchase_cost = NULL; } @@ -109,10 +122,10 @@ class LicensesController extends AdminController // Save the license seat data for ($x=0; $x<$license->seats; $x++) { $license_seat = new LicenseSeat(); - $license_seat->license_id = $insertedId; - $license_seat->user_id = Sentry::getId(); - $license_seat->assigned_to = 0; - $license_seat->notes = NULL; + $license_seat->license_id = $insertedId; + $license_seat->user_id = Sentry::getId(); + $license_seat->assigned_to = 0; + $license_seat->notes = NULL; $license_seat->save(); } @@ -156,7 +169,8 @@ class LicensesController extends AdminController // Show the page $license_options = array('' => 'Top Level') + DB::table('assets')->where('id', '!=', $licenseId)->lists('name', 'id'); $depreciation_list = array('0' => Lang::get('admin/licenses/form.no_depreciation')) + Depreciation::lists('name', 'id'); - return View::make('backend/licenses/edit', compact('license'))->with('license_options',$license_options)->with('depreciation_list',$depreciation_list); + $supplier_list = array('' => 'Select Supplier') + Supplier::orderBy('name', 'asc')->lists('name', 'id'); + return View::make('backend/licenses/edit', compact('license'))->with('license_options',$license_options)->with('depreciation_list',$depreciation_list)->with('supplier_list',$supplier_list); } @@ -184,14 +198,20 @@ class LicensesController extends AdminController if ($license->validate($new)) { // Update the license data - $license->name = e(Input::get('name')); - $license->serial = e(Input::get('serial')); - $license->license_email = e(Input::get('license_email')); - $license->license_name = e(Input::get('license_name')); - $license->notes = e(Input::get('notes')); - $license->order_number = e(Input::get('order_number')); - $license->depreciation_id = e(Input::get('depreciation_id')); + $license->name = e(Input::get('name')); + $license->serial = e(Input::get('serial')); + $license->license_email = e(Input::get('license_email')); + $license->license_name = e(Input::get('license_name')); + $license->notes = e(Input::get('notes')); + $license->order_number = e(Input::get('order_number')); + $license->depreciation_id = e(Input::get('depreciation_id')); + $license->purchase_order = e(Input::get('purchase_order')); + if ( e(Input::get('supplier_id')) == '') { + $license->supplier_id = NULL; + } else { + $license->supplier_id = e(Input::get('supplier_id')); + } // Update the asset data if ( e(Input::get('purchase_date')) == '') { @@ -200,6 +220,12 @@ class LicensesController extends AdminController $license->purchase_date = e(Input::get('purchase_date')); } + if ( e(Input::get('expiration_date')) == '') { + $license->expiration_date = NULL; + } else { + $license->expiration_date = e(Input::get('expiration_date')); + } + if ( e(Input::get('purchase_cost')) == '') { $license->purchase_cost = NULL; } else { @@ -245,10 +271,10 @@ class LicensesController extends AdminController for ($i=1; $i <= $difference; $i++) { //Create a seat for this license $license_seat = new LicenseSeat(); - $license_seat->license_id = $license->id; - $license_seat->user_id = Sentry::getId(); - $license_seat->assigned_to = 0; - $license_seat->notes = NULL; + $license_seat->license_id = $license->id; + $license_seat->user_id = Sentry::getId(); + $license_seat->assigned_to = 0; + $license_seat->notes = NULL; $license_seat->save(); } @@ -260,7 +286,7 @@ class LicensesController extends AdminController $logaction->note = abs($difference)." seats"; $log = $logaction->logaction('add seats'); } - $license->seats = e(Input::get('seats')); + $license->seats = e(Input::get('seats')); } // Was the asset created? @@ -328,28 +354,28 @@ 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'); - // Left join to get a list of assets and some other helpful info - $asset = DB::table('assets') - ->leftJoin('users', 'users.id', '=', 'assets.assigned_to') - ->select('assets.id', 'name', 'first_name', 'last_name','asset_tag', - DB::raw('concat (first_name," ",last_name) as full_name, assets.id as id')) - ->whereNull('assets.deleted_at') - ->get(); + // Left join to get a list of assets and some other helpful info + $asset = DB::table('assets') + ->leftJoin('users', 'users.id', '=', 'assets.assigned_to') + ->select('assets.id', 'name', 'first_name', 'last_name','asset_tag', + DB::raw('concat (first_name," ",last_name) as full_name, assets.id as id')) + ->whereNull('assets.deleted_at') + ->get(); - $asset_array = json_decode(json_encode($asset), true); - $asset_element[''] = 'Please select an asset'; + $asset_array = json_decode(json_encode($asset), true); + $asset_element[''] = 'Please select an asset'; - // Build a list out of the data results - for ($x=0; $xwith('users_list',$users_list)->with('asset_list',$asset_element); @@ -371,7 +397,7 @@ class LicensesController extends AdminController $rules = array( 'note' => 'alpha_space', - 'asset_id' => 'required_without:assigned_to', + 'asset_id' => 'required_without:assigned_to', ); // Create a new validator instance from our validation rules @@ -383,25 +409,25 @@ class LicensesController extends AdminController return Redirect::back()->withInput()->withErrors($validator); } - if ($assigned_to!='') { + if ($assigned_to!='') { // Check if the user exists - 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 (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_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')); - } + 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')); + } } @@ -412,8 +438,8 @@ class LicensesController extends AdminController // Redirect to the asset management page with error return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.not_found')); } - - if ( e(Input::get('asset_id')) == '') { + + if ( e(Input::get('asset_id')) == '') { $licenseseat->asset_id = NULL; } else { $licenseseat->asset_id = e(Input::get('asset_id')); @@ -503,8 +529,8 @@ class LicensesController extends AdminController $logaction->checkedout_to = $licenseseat->assigned_to; // Update the asset data - $licenseseat->assigned_to = '0'; - $licenseseat->asset_id = NULL; + $licenseseat->assigned_to = '0'; + $licenseseat->asset_id = NULL; // Was the asset updated? if($licenseseat->save()) { @@ -562,7 +588,8 @@ class LicensesController extends AdminController // 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',$license); + $supplier_list = array('' => 'Select Supplier') + Supplier::orderBy('name', 'asc')->lists('name', 'id'); + return View::make('backend/licenses/edit')->with('license_options',$license_options)->with('depreciation_list',$depreciation_list)->with('supplier_list',$supplier_list)->with('license',$license); } } diff --git a/app/database/migrations/2014_11_05_212408_add_fields_to_licenses.php b/app/database/migrations/2014_11_05_212408_add_fields_to_licenses.php new file mode 100644 index 0000000000..af59643fa3 --- /dev/null +++ b/app/database/migrations/2014_11_05_212408_add_fields_to_licenses.php @@ -0,0 +1,36 @@ +integer('supplier_id')->nullable()->default(NULL); + $table->date('expiration_date')->nullable(); + $table->string('purchase_order'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('licenses', function ($table) { + $table->dropColumn('supplier_id'); + $table->dropColumn('expiration_date'); + $table->dropColumn('purchase_order'); + }); + } + +} diff --git a/app/lang/en/admin/licenses/form.php b/app/lang/en/admin/licenses/form.php index b0bcc96ac2..6b9c71cc14 100755 --- a/app/lang/en/admin/licenses/form.php +++ b/app/lang/en/admin/licenses/form.php @@ -2,23 +2,26 @@ return array( - 'asset' => 'Asset', - 'checkin' => 'Checkin', - 'checkin' => 'Checkin', - 'cost' => 'Purchase Cost', - 'cost' => 'Purchase Cost', - 'create' => 'Create License', - 'date' => 'Purchase Date', - 'date' => 'Purchase Date', - 'depreciation' => 'Depreciation', - 'name' => 'Software Name', - 'no_depreciation' => 'Do Not Depreciate', - 'notes' => 'Notes', - 'order' => 'Order No.', - 'seats' => 'Seats', - 'serial' => 'Serial', - '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.' + 'asset' => 'Asset', + 'checkin' => 'Checkin', + 'checkin' => 'Checkin', + 'cost' => 'Purchase Cost', + 'cost' => 'Purchase Cost', + 'create' => 'Create License', + 'date' => 'Purchase Date', + 'date' => 'Purchase Date', + 'depreciation' => 'Depreciation', + 'expiration' => 'Expiration Date', + 'name' => 'Software Name', + 'no_depreciation' => 'Do Not Depreciate', + 'notes' => 'Notes', + 'order' => 'Order Number', + 'purchase_order' => 'Purchase Order Number', + 'seats' => 'Seats', + 'serial' => 'Serial', + 'supplier' => 'Supplier', + '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/suppliers/table.php b/app/lang/en/admin/suppliers/table.php index b413cd83d2..88adfc692b 100755 --- a/app/lang/en/admin/suppliers/table.php +++ b/app/lang/en/admin/suppliers/table.php @@ -1,24 +1,25 @@ 'Supplier Address', - 'assets' => 'Assets', - 'city' => 'City', - 'contact' => 'Contact Name', - 'country' => 'Country', - 'create' => 'Create Supplier', - 'email' => 'Email', - 'fax' => 'Fax', - 'id' => 'ID', - 'name' => 'Supplier Name', - 'notes' => 'Notes', - 'phone' => 'Phone', - 'state' => 'State', - 'suppliers' => 'Suppliers', - 'update' => 'Update Supplier', - 'url' => 'URL', - 'view' => 'View Supplier', - 'view_assets_for' => 'View Assets for', - 'zip' => 'Postal Code', + 'address' => 'Supplier Address', + 'assets' => 'Assets', + 'city' => 'City', + 'contact' => 'Contact Name', + 'country' => 'Country', + 'create' => 'Create Supplier', + 'email' => 'Email', + 'fax' => 'Fax', + 'id' => 'ID', + 'licenses' => 'Licenses', + 'name' => 'Supplier Name', + 'notes' => 'Notes', + 'phone' => 'Phone', + 'state' => 'State', + 'suppliers' => 'Suppliers', + 'update' => 'Update Supplier', + 'url' => 'URL', + 'view' => 'View Supplier', + 'view_assets_for' => 'View Assets for', + 'zip' => 'Postal Code', ); diff --git a/app/models/License.php b/app/models/License.php index 86f09f8b96..31466773a3 100755 --- a/app/models/License.php +++ b/app/models/License.php @@ -112,6 +112,11 @@ class License extends Elegant return $this->hasMany('LicenseSeat'); } + public function supplier() + { + return $this->belongsTo('Supplier','supplier_id'); + } + /** * Get depreciation class * @@ -147,7 +152,7 @@ class License extends Elegant - /** + /** * Handle depreciation */ public function depreciate() diff --git a/app/models/Supplier.php b/app/models/Supplier.php index a832ce2991..a256c6de30 100755 --- a/app/models/Supplier.php +++ b/app/models/Supplier.php @@ -4,19 +4,19 @@ class Supplier extends Elegant protected $softDelete = true; // Declare the rules for the form validation protected $rules = array( - 'name' => 'required|alpha_space|min:3|max:255|unique:suppliers,name,{id}', - 'address' => 'alpha_space|min:3|max:50', - 'address2' => 'alpha_space|min:2|max:50', - 'city' => 'alpha_space|min:3|max:255', + 'name' => 'required|alpha_space|min:3|max:255|unique:suppliers,name,{id}', + 'address' => 'alpha_space|min:3|max:50', + 'address2' => 'alpha_space|min:2|max:50', + 'city' => 'alpha_space|min:3|max:255', 'state' => 'alpha_space|min:0|max:32', 'country' => 'alpha_space|min:0|max:2', - 'fax' => 'alpha_space|min:7|max:20', - 'phone' => 'alpha_space|min:7|max:20', + 'fax' => 'alpha_space|min:7|max:20', + 'phone' => 'alpha_space|min:7|max:20', 'contact' => 'alpha_space|min:0|max:100', 'notes' => 'alpha_space|min:0|max:255', - 'email' => 'email|min:5|max:150', + 'email' => 'email|min:5|max:150', 'zip' => 'alpha_space|min:0|max:10', - 'url' => 'alpha_space|min:3|max:250', + 'url' => 'alpha_space|min:3|max:250', ); @@ -30,6 +30,15 @@ class Supplier extends Elegant return $this->hasMany('Asset', 'supplier_id')->count(); } + public function licenses() + { + return $this->hasMany('License', 'supplier_id'); + } + + public function num_licenses() + { + return $this->hasMany('License', 'supplier_id')->count(); + } public function addhttp($url) { diff --git a/app/views/backend/licenses/edit.blade.php b/app/views/backend/licenses/edit.blade.php index 1134e11187..0f604176d6 100755 --- a/app/views/backend/licenses/edit.blade.php +++ b/app/views/backend/licenses/edit.blade.php @@ -33,7 +33,7 @@ - +
@@ -44,6 +44,7 @@
+
@@ -54,6 +55,7 @@
+
@@ -62,6 +64,7 @@
+
@@ -70,6 +73,7 @@
+
@@ -80,6 +84,26 @@
+ +
+ +
+ + + {{ $errors->first('expiration_date', ' :message') }} +
+
+ + +
+ +
+ {{ Form::select('supplier_id', $supplier_list , Input::old('supplier_id', $license->supplier_id), array('class'=>'select2', 'style'=>'min-width:350px')) }} + {{ $errors->first('supplier_id', ' :message') }} +
+
+ +
@@ -110,6 +134,15 @@
+ +
+ +
+ + {{ $errors->first('purchase_order', ' :message') }} +
+
+
@@ -119,7 +152,7 @@
- +
diff --git a/app/views/backend/licenses/view.blade.php b/app/views/backend/licenses/view.blade.php index e90fb024f4..252e560374 100755 --- a/app/views/backend/licenses/view.blade.php +++ b/app/views/backend/licenses/view.blade.php @@ -43,6 +43,17 @@
@lang('admin/licenses/form.to_email'): {{ $license->license_email }}
@endif +@if ($license->supplier_id) +
@lang('admin/licenses/form.supplier'): + + {{{ $license->supplier->name }}} +
+@endif + +@if ($license->expiration_date > 0) +
@lang('admin/licenses/form.expiration'): {{ $license->expiration_date }}
+@endif + @if ($license->notes)
@lang('admin/licenses/form.notes'): {{ $license->notes }}
@endif @@ -104,7 +115,7 @@ @if ($licensedto->asset_id) - {{ $licensedto->asset->name }} {{ $licensedto->asset->asset_tag }} + {{ $licensedto->asset->name }} {{ $licensedto->asset->asset_tag }} @endif @@ -188,7 +199,9 @@

@lang('general.moreinfo'):