A free open source IT asset/license management system
Added license categories
snipe7b8362b64c1f
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.phpindex 93d198cd4f..87c8216320 100644--- a/app/Helpers/Helper.php+++ b/app/Helpers/Helper.php@@ -330,7 +330,14 @@ class Helper*/public static function categoryTypeList(){- $category_types = array('' => '','accessory' => 'Accessory', 'asset' => 'Asset', 'consumable' => 'Consumable','component' => 'Component');+ $category_types = array(+ '' => '',+ 'accessory' => 'Accessory',+ 'asset' => 'Asset',+ 'consumable' => 'Consumable',+ 'component' => 'Component',+ 'license' => 'License'+ );return $category_types;}@@ -738,6 +745,7 @@ class Helperstatic $max_size = -1;if ($max_size < 0) {+// Start with post_max_size.$post_max_size = Helper::parse_size(ini_get('post_max_size'));if ($post_max_size > 0) {@@ -751,6 +759,7 @@ class Helper$max_size = $upload_max;}}+return $max_size;}diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.phpindex 006eea0ff6..71ee88c1e1 100644--- a/app/Http/Controllers/Api/CategoriesController.php+++ b/app/Http/Controllers/Api/CategoriesController.php@@ -21,10 +21,10 @@ class CategoriesController extends Controllerpublic function index(Request $request){$this->authorize('view', Category::class);- $allowed_columns = ['id', 'name','category_type', 'category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count', 'image'];+ $allowed_columns = ['id', 'name','category_type', 'category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count','licenses_count', 'image'];$categories = Category::select(['id', 'created_at', 'updated_at', 'name','category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email','image'])- ->withCount('assets', 'accessories', 'consumables', 'components');+ ->withCount('assets', 'accessories', 'consumables', 'components','licenses');if ($request->has('search')) {$categories = $categories->TextSearch($request->input('search'));diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.phpindex 2fb16a8538..2d0ef69191 100644--- a/app/Http/Controllers/Api/LicensesController.php+++ b/app/Http/Controllers/Api/LicensesController.php@@ -25,7 +25,7 @@ class LicensesController extends Controllerpublic function index(Request $request){$this->authorize('view', License::class);- $licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier')->withCount('freeSeats'));+ $licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier','category')->withCount('freeSeats'));if ($request->has('company_id')) {@@ -64,6 +64,10 @@ class LicensesController extends Controller$licenses->where('supplier_id','=',$request->input('supplier_id'));}+ if ($request->has('category_i')) {+ $licenses->where('category_i','=',$request->input('category_i'));+ }+if ($request->has('depreciation_id')) {$licenses->where('depreciation_id','=',$request->input('depreciation_id'));}@@ -90,11 +94,14 @@ class LicensesController extends Controllercase 'supplier':$licenses = $licenses->leftJoin('suppliers', 'licenses.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order);break;+ case 'category':+ $licenses = $licenses->leftJoin('categories', 'licenses.category_id', '=', 'categories.id')->orderBy('categories.name', $order);+ break;case 'company':$licenses = $licenses->leftJoin('companies', 'licenses.company_id', '=', 'companies.id')->orderBy('companies.name', $order);break;default:- $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','company','license_name','license_email','free_seats_count','seats'];+ $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','company','category','license_name','license_email','free_seats_count','seats'];$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';$licenses = $licenses->orderBy($sort, $order);break;diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.phpindex e4b00a94d8..c2024f9580 100755--- a/app/Http/Controllers/LicensesController.php+++ b/app/Http/Controllers/LicensesController.php@@ -107,6 +107,7 @@ class LicensesController extends Controller$license->seats = $request->input('seats');$license->serial = $request->input('serial');$license->supplier_id = $request->input('supplier_id');+ $license->category_id = $request->input('category_id');$license->termination_date = $request->input('termination_date');$license->user_id = Auth::id();@@ -182,6 +183,7 @@ class LicensesController extends Controller$license->seats = e($request->input('seats'));$license->manufacturer_id = $request->input('manufacturer_id');$license->supplier_id = $request->input('supplier_id');+ $license->category_id = $request->input('category_id');if ($license->save()) {return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success'));@@ -420,7 +422,6 @@ class LicensesController extends Controller$return_to = Asset::find($licenseSeat->asset_id);}- \Log::debug($licenseSeat->assigned_to);// Update the asset data$licenseSeat->assigned_to = null;$licenseSeat->asset_id = null;diff --git a/app/Http/Transformers/CategoriesTransformer.php b/app/Http/Transformers/CategoriesTransformer.phpindex 77bf07aa29..fabbd36b7c 100644--- a/app/Http/Transformers/CategoriesTransformer.php+++ b/app/Http/Transformers/CategoriesTransformer.php@@ -34,6 +34,7 @@ class CategoriesTransformer'accessories_count' => $category->accessories_count,'consumables_count' => $category->consumables_count,'components_count' => $category->components_count,+ 'licenses_count' => $category->licenses_count,'created_at' => Helper::getFormattedDateObject($category->created_at, 'datetime'),'updated_at' => Helper::getFormattedDateObject($category->updated_at, 'datetime'),];diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.phpindex 5cf5c7c477..fa7630e8de 100644--- a/app/Http/Transformers/LicensesTransformer.php+++ b/app/Http/Transformers/LicensesTransformer.php@@ -38,6 +38,7 @@ class LicensesTransformer'license_email' => e($license->license_email),'maintained' => ($license->maintained == 1) ? true : false,'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id,'name'=> e($license->supplier->name)] : null,+ 'category' => ($license->category) ? ['id' => (int) $license->category->id,'name'=> e($license->category->name)] : null,'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),'user_can_checkout' => (bool) ($license->free_seats_count > 0),diff --git a/app/Models/Category.php b/app/Models/Category.phpindex 63a3104484..8a598e9b10 100755--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -33,7 +33,7 @@ class Category extends SnipeModel'name' => 'required|min:1|max:255|unique_undeleted','require_acceptance' => 'boolean','use_default_eula' => 'boolean',- 'category_type' => 'required|in:asset,accessory,consumable,component',+ 'category_type' => 'required|in:asset,accessory,consumable,component,license',);/**@@ -74,6 +74,11 @@ class Category extends SnipeModelreturn $this->hasMany('\App\Models\Accessory');}+ public function licenses()+ {+ return $this->hasMany('\App\Models\License');+ }+public function consumables(){return $this->hasMany('\App\Models\Consumable');diff --git a/app/Models/License.php b/app/Models/License.phpindex 6b22903532..494d8ca8b0 100755--- a/app/Models/License.php+++ b/app/Models/License.php@@ -41,6 +41,7 @@ class License extends Depreciable'license_email' => 'email|nullable|max:120','license_name' => 'string|nullable|max:100','notes' => 'string|nullable',+ 'category_id' => 'integer','company_id' => 'integer|nullable',);@@ -57,6 +58,7 @@ class License extends Depreciable'license_name', //actually licensed_to'maintained','manufacturer_id',+ 'category_id','name','notes','order_number',@@ -83,7 +85,6 @@ class License extends Depreciablestatic::updating(function ($license) {$newSeatCount = $license->getAttributes()['seats'];$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;- // dd($oldSeatCount.' '.$newSeatCount);return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount);});}@@ -98,7 +99,7 @@ class License extends Depreciable$change = abs($oldSeats - $newSeats);if ($oldSeats > $newSeats) {$license->load('licenseseats.user');- // dd("Here");+// Need to delete seats... lets see if if we have enough.$seatsAvailableForDelete = $license->licenseseats->reject(function ($seat) {return (!! $seat->assigned_to) || (!! $seat->asset_id);@@ -176,11 +177,39 @@ class License extends Depreciablereturn $this->belongsTo('\App\Models\Company', 'company_id');}+ public function category()+ {+ return $this->belongsTo('\App\Models\Category', 'category_id');+ }+public function manufacturer(){return $this->belongsTo('\App\Models\Manufacturer', 'manufacturer_id');}+ public function checkin_email()+ {+ return $this->model->category->checkin_email;+ }++ public function requireAcceptance()+ {+ return $this->category->require_acceptance;+ }++ public function getEula()+ {+ $Parsedown = new \Parsedown();++ if ($this->category->eula_text) {+ return $Parsedown->text(e($this->category->eula_text));+ } elseif ($this->category->use_default_eula == '1') {+ return $Parsedown->text(e(Setting::getSettings()->default_eula_text));+ } else {+ return false;+ }+ }+/*** Get the assigned user*/diff --git a/app/Notifications/CheckinLicenseNotification.php b/app/Notifications/CheckinLicenseNotification.phpindex 6f5edcffb6..12212b7c4c 100644--- a/app/Notifications/CheckinLicenseNotification.php+++ b/app/Notifications/CheckinLicenseNotification.php@@ -31,6 +31,7 @@ class CheckinLicenseNotification extends Notification$this->admin = $params['admin'];$this->note = '';$this->settings = $params['settings'];+ $this->target_type = $params['target_type'];if (array_key_exists('note', $params)) {$this->note = $params['note'];@@ -53,7 +54,10 @@ class CheckinLicenseNotification extends Notification}- $notifyBy[] = 'mail';+ if (($this->target_type == \App\Models\User::class) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula())))+ {+ $notifyBy[] = 'mail';+ }return $notifyBy;}diff --git a/app/Notifications/CheckoutLicenseNotification.php b/app/Notifications/CheckoutLicenseNotification.phpindex 961ee10a3c..5ed460c6ad 100644--- a/app/Notifications/CheckoutLicenseNotification.php+++ b/app/Notifications/CheckoutLicenseNotification.php@@ -33,6 +33,7 @@ class CheckoutLicenseNotification extends Notification$this->note = '';$this->target_type = $params['target_type'];$this->settings = $params['settings'];+ $this->target_type = $params['target_type'];if (array_key_exists('note', $params)) {$this->note = $params['note'];@@ -56,7 +57,8 @@ class CheckoutLicenseNotification extends Notification$notifyBy[] = 'slack';}- if ($this->target_type == \App\Models\User::class) {+ if (($this->target_type == \App\Models\User::class) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula())))+ {$notifyBy[] = 'mail';}diff --git a/app/Presenters/CategoryPresenter.php b/app/Presenters/CategoryPresenter.phpindex 0df0bf13c6..bceff26c6b 100644--- a/app/Presenters/CategoryPresenter.php+++ b/app/Presenters/CategoryPresenter.php@@ -69,6 +69,12 @@ class CategoryPresenter extends Presenter"sortable" => true,"title" => trans('general.components'),"visible" => true+ ], [+ "field" => "licenses_count",+ "searchable" => false,+ "sortable" => true,+ "title" => trans('general.licenses'),+ "visible" => true], ["field" => "eula","searchable" => false,diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.phpindex 249170379d..0cc226dc48 100644--- a/app/Presenters/LicensePresenter.php+++ b/app/Presenters/LicensePresenter.php@@ -61,6 +61,14 @@ class LicensePresenter extends Presenter"searchable" => true,"sortable" => true,"title" => trans('admin/licenses/form.to_name'),+ ], [+ "field" => "category",+ "searchable" => true,+ "sortable" => true,+ "switchable" => true,+ "title" => trans('general.category'),+ "visible" => false,+ "formatter" => "categoriesLinkObjFormatter"], ["field" => "supplier","searchable" => true,diff --git a/database/migrations/2018_05_04_073223_add_category_to_licenses.php b/database/migrations/2018_05_04_073223_add_category_to_licenses.phpnew file mode 100644index 0000000000..7425eba13a--- /dev/null+++ b/database/migrations/2018_05_04_073223_add_category_to_licenses.php@@ -0,0 +1,35 @@+<?php++use Illuminate\Support\Facades\Schema;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;+++class AddCategoryToLicenses extends Migration+{+ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {++ Schema::table('licenses', function (Blueprint $table) {+ $table->integer('category_id')->nullable()->default(null);+ });++ }++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ Schema::table('licenses', function (Blueprint $table) {+ $table->dropColumn('category_id');+ });+ }+}diff --git a/database/migrations/2018_05_04_075235_add_update_license_category.php b/database/migrations/2018_05_04_075235_add_update_license_category.phpnew file mode 100644index 0000000000..4997b0a1cf--- /dev/null+++ b/database/migrations/2018_05_04_075235_add_update_license_category.php@@ -0,0 +1,44 @@+<?php++use Illuminate\Support\Facades\Schema;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;+use App\Models\Category;+use App\Models\License;++class AddUpdateLicenseCategory extends Migration+{+ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {++ // Create a new software category and assign all of the existing licenses to it+ $category = new Category;+ $category->name = 'Misc Software';+ $category->category_type = 'license';++ if ($category->save()) {+ License::whereNull('category_id')->withTrashed()+ ->update(['category_id' => $category->id]);+ }++ }++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {++ App\Models\Category::where('name', 'Misc Software')->forceDelete();++ License::whereNotNull('category_id')+ ->update(['category_id' => null]);+ }+}diff --git a/resources/views/categories/view.blade.php b/resources/views/categories/view.blade.phpindex 0316266150..304ccbe92b 100644--- a/resources/views/categories/view.blade.php+++ b/resources/views/categories/view.blade.php@@ -68,6 +68,15 @@"fileName": "export-{{ str_slug($category->name) }}-components-{{ date('Y-m-d') }}","ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]}'+ @elseif ($category->category_type=='license')+ data-columns="{{ \App\Presenters\LicensePresenter::dataTableLayout() }}"+ data-cookie-id-table="categoryLicenseTable"+ id="categoryLicenseTable"+ data-id-table="categoryLicenseTable"+ data-export-options='{+ "fileName": "export-{{ str_slug($category->name) }}-licenses-{{ date('Y-m-d') }}",+ "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]+ }'@endifdata-pagination="true"diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.phpindex 5d284cd54b..c18bc420ab 100755--- a/resources/views/dashboard.blade.php+++ b/resources/views/dashboard.blade.php@@ -254,6 +254,7 @@<th class="col-sm-1" data-visible="true" data-field="accessories_count" data-sortable="true"><i class="fa fa-keyboard-o"></i></th><th class="col-sm-1" data-visible="true" data-field="consumables_count" data-sortable="true"><i class="fa fa-tint"></i></th><th class="col-sm-1" data-visible="true" data-field="components_count" data-sortable="true"><i class="fa fa-hdd-o"></i></th>+ <th class="col-sm-1" data-visible="true" data-field="licenses_count" data-sortable="true"><i class="fa fa-floppy-o"></i></th></tr></thead></table>diff --git a/resources/views/licenses/edit.blade.php b/resources/views/licenses/edit.blade.phpindex 717379e9d1..18b55acbd1 100755--- a/resources/views/licenses/edit.blade.php+++ b/resources/views/licenses/edit.blade.php@@ -9,7 +9,7 @@{{-- Page content --}}@section('inputFields')@include ('partials.forms.edit.name', ['translated_name' => trans('admin/licenses/form.name')])-+@include ('partials.forms.edit.category-select', ['translated_name' => trans('admin/categories/general.category_name'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'license'])<!-- Serial--><div class="form-group {{ $errors->has('serial') ? ' has-error' : '' }}"><label for="serial" class="col-md-3 control-label">{{ trans('admin/licenses/form.license_key') }}</label>