Added license categories

This commit is contained in:
snipe 2018-05-04 21:01:38 -07:00
parent 188538651a
commit 7b8362b64c
17 changed files with 174 additions and 12 deletions

View file

@ -330,7 +330,14 @@ class Helper
*/ */
public static function categoryTypeList() 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; return $category_types;
} }
@ -738,6 +745,7 @@ class Helper
static $max_size = -1; static $max_size = -1;
if ($max_size < 0) { if ($max_size < 0) {
// Start with post_max_size. // Start with post_max_size.
$post_max_size = Helper::parse_size(ini_get('post_max_size')); $post_max_size = Helper::parse_size(ini_get('post_max_size'));
if ($post_max_size > 0) { if ($post_max_size > 0) {
@ -751,6 +759,7 @@ class Helper
$max_size = $upload_max; $max_size = $upload_max;
} }
} }
return $max_size; return $max_size;
} }

View file

@ -21,10 +21,10 @@ class CategoriesController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$this->authorize('view', Category::class); $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']) $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')) { if ($request->has('search')) {
$categories = $categories->TextSearch($request->input('search')); $categories = $categories->TextSearch($request->input('search'));

View file

@ -25,7 +25,7 @@ class LicensesController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$this->authorize('view', License::class); $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')) { if ($request->has('company_id')) {
@ -64,6 +64,10 @@ class LicensesController extends Controller
$licenses->where('supplier_id','=',$request->input('supplier_id')); $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')) { if ($request->has('depreciation_id')) {
$licenses->where('depreciation_id','=',$request->input('depreciation_id')); $licenses->where('depreciation_id','=',$request->input('depreciation_id'));
} }
@ -90,11 +94,14 @@ class LicensesController extends Controller
case 'supplier': case 'supplier':
$licenses = $licenses->leftJoin('suppliers', 'licenses.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order); $licenses = $licenses->leftJoin('suppliers', 'licenses.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order);
break; break;
case 'category':
$licenses = $licenses->leftJoin('categories', 'licenses.category_id', '=', 'categories.id')->orderBy('categories.name', $order);
break;
case 'company': case 'company':
$licenses = $licenses->leftJoin('companies', 'licenses.company_id', '=', 'companies.id')->orderBy('companies.name', $order); $licenses = $licenses->leftJoin('companies', 'licenses.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
break; break;
default: 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'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
$licenses = $licenses->orderBy($sort, $order); $licenses = $licenses->orderBy($sort, $order);
break; break;

View file

@ -107,6 +107,7 @@ class LicensesController extends Controller
$license->seats = $request->input('seats'); $license->seats = $request->input('seats');
$license->serial = $request->input('serial'); $license->serial = $request->input('serial');
$license->supplier_id = $request->input('supplier_id'); $license->supplier_id = $request->input('supplier_id');
$license->category_id = $request->input('category_id');
$license->termination_date = $request->input('termination_date'); $license->termination_date = $request->input('termination_date');
$license->user_id = Auth::id(); $license->user_id = Auth::id();
@ -182,6 +183,7 @@ class LicensesController extends Controller
$license->seats = e($request->input('seats')); $license->seats = e($request->input('seats'));
$license->manufacturer_id = $request->input('manufacturer_id'); $license->manufacturer_id = $request->input('manufacturer_id');
$license->supplier_id = $request->input('supplier_id'); $license->supplier_id = $request->input('supplier_id');
$license->category_id = $request->input('category_id');
if ($license->save()) { if ($license->save()) {
return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success')); 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); $return_to = Asset::find($licenseSeat->asset_id);
} }
\Log::debug($licenseSeat->assigned_to);
// Update the asset data // Update the asset data
$licenseSeat->assigned_to = null; $licenseSeat->assigned_to = null;
$licenseSeat->asset_id = null; $licenseSeat->asset_id = null;

View file

@ -34,6 +34,7 @@ class CategoriesTransformer
'accessories_count' => $category->accessories_count, 'accessories_count' => $category->accessories_count,
'consumables_count' => $category->consumables_count, 'consumables_count' => $category->consumables_count,
'components_count' => $category->components_count, 'components_count' => $category->components_count,
'licenses_count' => $category->licenses_count,
'created_at' => Helper::getFormattedDateObject($category->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($category->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($category->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($category->updated_at, 'datetime'),
]; ];

View file

@ -38,6 +38,7 @@ class LicensesTransformer
'license_email' => e($license->license_email), 'license_email' => e($license->license_email),
'maintained' => ($license->maintained == 1) ? true : false, 'maintained' => ($license->maintained == 1) ? true : false,
'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id,'name'=> e($license->supplier->name)] : null, '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'), 'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
'user_can_checkout' => (bool) ($license->free_seats_count > 0), 'user_can_checkout' => (bool) ($license->free_seats_count > 0),

View file

@ -33,7 +33,7 @@ class Category extends SnipeModel
'name' => 'required|min:1|max:255|unique_undeleted', 'name' => 'required|min:1|max:255|unique_undeleted',
'require_acceptance' => 'boolean', 'require_acceptance' => 'boolean',
'use_default_eula' => '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 SnipeModel
return $this->hasMany('\App\Models\Accessory'); return $this->hasMany('\App\Models\Accessory');
} }
public function licenses()
{
return $this->hasMany('\App\Models\License');
}
public function consumables() public function consumables()
{ {
return $this->hasMany('\App\Models\Consumable'); return $this->hasMany('\App\Models\Consumable');

View file

@ -41,6 +41,7 @@ class License extends Depreciable
'license_email' => 'email|nullable|max:120', 'license_email' => 'email|nullable|max:120',
'license_name' => 'string|nullable|max:100', 'license_name' => 'string|nullable|max:100',
'notes' => 'string|nullable', 'notes' => 'string|nullable',
'category_id' => 'integer',
'company_id' => 'integer|nullable', 'company_id' => 'integer|nullable',
); );
@ -57,6 +58,7 @@ class License extends Depreciable
'license_name', //actually licensed_to 'license_name', //actually licensed_to
'maintained', 'maintained',
'manufacturer_id', 'manufacturer_id',
'category_id',
'name', 'name',
'notes', 'notes',
'order_number', 'order_number',
@ -83,7 +85,6 @@ class License extends Depreciable
static::updating(function ($license) { static::updating(function ($license) {
$newSeatCount = $license->getAttributes()['seats']; $newSeatCount = $license->getAttributes()['seats'];
$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0; $oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
// dd($oldSeatCount.' '.$newSeatCount);
return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount); return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount);
}); });
} }
@ -98,7 +99,7 @@ class License extends Depreciable
$change = abs($oldSeats - $newSeats); $change = abs($oldSeats - $newSeats);
if ($oldSeats > $newSeats) { if ($oldSeats > $newSeats) {
$license->load('licenseseats.user'); $license->load('licenseseats.user');
// dd("Here");
// Need to delete seats... lets see if if we have enough. // Need to delete seats... lets see if if we have enough.
$seatsAvailableForDelete = $license->licenseseats->reject(function ($seat) { $seatsAvailableForDelete = $license->licenseseats->reject(function ($seat) {
return (!! $seat->assigned_to) || (!! $seat->asset_id); return (!! $seat->assigned_to) || (!! $seat->asset_id);
@ -176,11 +177,39 @@ class License extends Depreciable
return $this->belongsTo('\App\Models\Company', 'company_id'); return $this->belongsTo('\App\Models\Company', 'company_id');
} }
public function category()
{
return $this->belongsTo('\App\Models\Category', 'category_id');
}
public function manufacturer() public function manufacturer()
{ {
return $this->belongsTo('\App\Models\Manufacturer', 'manufacturer_id'); 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 * Get the assigned user
*/ */

View file

@ -31,6 +31,7 @@ class CheckinLicenseNotification extends Notification
$this->admin = $params['admin']; $this->admin = $params['admin'];
$this->note = ''; $this->note = '';
$this->settings = $params['settings']; $this->settings = $params['settings'];
$this->target_type = $params['target_type'];
if (array_key_exists('note', $params)) { if (array_key_exists('note', $params)) {
$this->note = $params['note']; $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; return $notifyBy;
} }

View file

@ -33,6 +33,7 @@ class CheckoutLicenseNotification extends Notification
$this->note = ''; $this->note = '';
$this->target_type = $params['target_type']; $this->target_type = $params['target_type'];
$this->settings = $params['settings']; $this->settings = $params['settings'];
$this->target_type = $params['target_type'];
if (array_key_exists('note', $params)) { if (array_key_exists('note', $params)) {
$this->note = $params['note']; $this->note = $params['note'];
@ -56,7 +57,8 @@ class CheckoutLicenseNotification extends Notification
$notifyBy[] = 'slack'; $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'; $notifyBy[] = 'mail';
} }

View file

@ -69,6 +69,12 @@ class CategoryPresenter extends Presenter
"sortable" => true, "sortable" => true,
"title" => trans('general.components'), "title" => trans('general.components'),
"visible" => true "visible" => true
], [
"field" => "licenses_count",
"searchable" => false,
"sortable" => true,
"title" => trans('general.licenses'),
"visible" => true
], [ ], [
"field" => "eula", "field" => "eula",
"searchable" => false, "searchable" => false,

View file

@ -61,6 +61,14 @@ class LicensePresenter extends Presenter
"searchable" => true, "searchable" => true,
"sortable" => true, "sortable" => true,
"title" => trans('admin/licenses/form.to_name'), "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", "field" => "supplier",
"searchable" => true, "searchable" => true,

View file

@ -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');
});
}
}

View file

@ -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]);
}
}

View file

@ -68,6 +68,15 @@
"fileName": "export-{{ str_slug($category->name) }}-components-{{ date('Y-m-d') }}", "fileName": "export-{{ str_slug($category->name) }}-components-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] "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"]
}'
@endif @endif
data-pagination="true" data-pagination="true"

View file

@ -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="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="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="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> </tr>
</thead> </thead>
</table> </table>

View file

@ -9,7 +9,7 @@
{{-- Page content --}} {{-- Page content --}}
@section('inputFields') @section('inputFields')
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/licenses/form.name')]) @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--> <!-- Serial-->
<div class="form-group {{ $errors->has('serial') ? ' has-error' : '' }}"> <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> <label for="serial" class="col-md-3 control-label">{{ trans('admin/licenses/form.license_key') }}</label>