mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-23 11:43:47 -08:00
Merge pull request #14346 from snipe/feature/sc-18728
Added `min_amt` functionality to licenses
This commit is contained in:
commit
ee75df0f0a
|
@ -11,6 +11,7 @@ use App\Models\CustomFieldset;
|
|||
use App\Models\Depreciation;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\License;
|
||||
use Crypt;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Image;
|
||||
|
@ -715,18 +716,19 @@ class Helper
|
|||
*/
|
||||
public static function checkLowInventory()
|
||||
{
|
||||
$alert_threshold = \App\Models\Setting::getSettings()->alert_threshold;
|
||||
$consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();
|
||||
$accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get();
|
||||
$components = Component::whereNotNull('min_amt')->get();
|
||||
$asset_models = AssetModel::where('min_amt', '>', 0)->get();
|
||||
$licenses = License::where('min_amt', '>', 0)->get();
|
||||
|
||||
$avail_consumables = 0;
|
||||
$items_array = [];
|
||||
$all_count = 0;
|
||||
|
||||
foreach ($consumables as $consumable) {
|
||||
$avail = $consumable->numRemaining();
|
||||
if ($avail < ($consumable->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
|
||||
if ($avail < ($consumable->min_amt) + $alert_threshold) {
|
||||
if ($consumable->qty > 0) {
|
||||
$percent = number_format((($avail / $consumable->qty) * 100), 0);
|
||||
} else {
|
||||
|
@ -745,7 +747,7 @@ class Helper
|
|||
|
||||
foreach ($accessories as $accessory) {
|
||||
$avail = $accessory->qty - $accessory->users_count;
|
||||
if ($avail < ($accessory->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
|
||||
if ($avail < ($accessory->min_amt) + $alert_threshold) {
|
||||
if ($accessory->qty > 0) {
|
||||
$percent = number_format((($avail / $accessory->qty) * 100), 0);
|
||||
} else {
|
||||
|
@ -764,7 +766,7 @@ class Helper
|
|||
|
||||
foreach ($components as $component) {
|
||||
$avail = $component->numRemaining();
|
||||
if ($avail < ($component->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
|
||||
if ($avail < ($component->min_amt) + $alert_threshold) {
|
||||
if ($component->qty > 0) {
|
||||
$percent = number_format((($avail / $component->qty) * 100), 0);
|
||||
} else {
|
||||
|
@ -787,7 +789,7 @@ class Helper
|
|||
$total_owned = $asset->where('model_id', '=', $asset_model->id)->count();
|
||||
$avail = $asset->where('model_id', '=', $asset_model->id)->whereNull('assigned_to')->count();
|
||||
|
||||
if ($avail < ($asset_model->min_amt)+ \App\Models\Setting::getSettings()->alert_threshold) {
|
||||
if ($avail < ($asset_model->min_amt) + $alert_threshold) {
|
||||
if ($avail > 0) {
|
||||
$percent = number_format((($avail / $total_owned) * 100), 0);
|
||||
} else {
|
||||
|
@ -803,6 +805,26 @@ class Helper
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($licenses as $license){
|
||||
$avail = $license->remaincount();
|
||||
if ($avail < ($license->min_amt) + $alert_threshold) {
|
||||
if ($avail > 0) {
|
||||
$percent = number_format((($avail / $license->min_amt) * 100), 0);
|
||||
} else {
|
||||
$percent = 100;
|
||||
}
|
||||
|
||||
$items_array[$all_count]['id'] = $license->id;
|
||||
$items_array[$all_count]['name'] = $license->name;
|
||||
$items_array[$all_count]['type'] = 'licenses';
|
||||
$items_array[$all_count]['percent'] = $percent;
|
||||
$items_array[$all_count]['remaining'] = $avail;
|
||||
$items_array[$all_count]['min_amt'] = $license->min_amt;
|
||||
$all_count++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $items_array;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ class LicensesController extends Controller
|
|||
'seats',
|
||||
'termination_date',
|
||||
'depreciation_id',
|
||||
'min_amt',
|
||||
];
|
||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
||||
$licenses = $licenses->orderBy($sort, $order);
|
||||
|
|
|
@ -99,6 +99,7 @@ class LicensesController extends Controller
|
|||
$license->category_id = $request->input('category_id');
|
||||
$license->termination_date = $request->input('termination_date');
|
||||
$license->user_id = Auth::id();
|
||||
$license->min_amt = $request->input('min_amt');
|
||||
|
||||
if ($license->save()) {
|
||||
return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.create.success'));
|
||||
|
@ -176,6 +177,7 @@ class LicensesController extends Controller
|
|||
$license->manufacturer_id = $request->input('manufacturer_id');
|
||||
$license->supplier_id = $request->input('supplier_id');
|
||||
$license->category_id = $request->input('category_id');
|
||||
$license->min_amt = $request->input('min_amt');
|
||||
|
||||
if ($license->save()) {
|
||||
return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success'));
|
||||
|
@ -245,12 +247,6 @@ class LicensesController extends Controller
|
|||
$available_seats_count = $license->availCount()->count();
|
||||
$checkedout_seats_count = ($total_seats_count - $available_seats_count);
|
||||
|
||||
\Log::debug('Total: '.$total_seats_count);
|
||||
\Log::debug('Users: '.$users_count);
|
||||
\Log::debug('Available: '.$available_seats_count);
|
||||
\Log::debug('Checkedout: '.$checkedout_seats_count);
|
||||
|
||||
|
||||
$this->authorize('view', $license);
|
||||
return view('licenses.view', compact('license'))
|
||||
->with('users_count', $users_count)
|
||||
|
|
|
@ -27,8 +27,8 @@ class LicensesTransformer
|
|||
'company' => ($license->company) ? ['id' => (int) $license->company->id, 'name'=> e($license->company->name)] : null,
|
||||
'manufacturer' => ($license->manufacturer) ? ['id' => (int) $license->manufacturer->id, 'name'=> e($license->manufacturer->name)] : null,
|
||||
'product_key' => (Gate::allows('viewKeys', License::class)) ? e($license->serial) : '------------',
|
||||
'order_number' => e($license->order_number),
|
||||
'purchase_order' => e($license->purchase_order),
|
||||
'order_number' => ($license->order_number) ? e($license->order_number) : null,
|
||||
'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : null,
|
||||
'purchase_date' => Helper::getFormattedDateObject($license->purchase_date, 'date'),
|
||||
'termination_date' => Helper::getFormattedDateObject($license->termination_date, 'date'),
|
||||
'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
|
||||
|
@ -38,8 +38,9 @@ class LicensesTransformer
|
|||
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
|
||||
'seats' => (int) $license->seats,
|
||||
'free_seats_count' => (int) $license->free_seats_count,
|
||||
'license_name' => e($license->license_name),
|
||||
'license_email' => e($license->license_email),
|
||||
'min_amt' => ($license->min_amt) ? (int) ($license->min_amt) : null,
|
||||
'license_name' => ($license->license_name) ? e($license->license_name) : null,
|
||||
'license_email' => ($license->license_email) ? e($license->license_email) : null,
|
||||
'reassignable' => ($license->reassignable == 1) ? true : false,
|
||||
'maintained' => ($license->maintained == 1) ? true : false,
|
||||
'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id, 'name'=> e($license->supplier->name)] : null,
|
||||
|
|
|
@ -53,6 +53,7 @@ class License extends Depreciable
|
|||
'purchase_date' => 'date_format:Y-m-d|nullable|max:10',
|
||||
'expiration_date' => 'date_format:Y-m-d|nullable|max:10',
|
||||
'termination_date' => 'date_format:Y-m-d|nullable|max:10',
|
||||
'min_amt' => 'numeric|nullable|gte:0',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -81,6 +82,7 @@ class License extends Depreciable
|
|||
'supplier_id',
|
||||
'termination_date',
|
||||
'user_id',
|
||||
'min_amt',
|
||||
];
|
||||
|
||||
use Searchable;
|
||||
|
|
|
@ -89,7 +89,14 @@ class LicensePresenter extends Presenter
|
|||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'title' => trans('admin/accessories/general.remaining'),
|
||||
], [
|
||||
],
|
||||
[
|
||||
'field' => 'min_amt',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'title' => trans('mail.min_QTY'),
|
||||
'formatter' => 'minAmtFormatter',
|
||||
],[
|
||||
'field' => 'purchase_date',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddMinQtyToLicenses extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('licenses', function (Blueprint $table) {
|
||||
$table->integer('min_amt')->nullable()->default(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('licenses', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('licenses', 'min_amt')) {
|
||||
$table->dropColumn('min_amt');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -45,4 +45,7 @@ return array(
|
|||
|
||||
],
|
||||
],
|
||||
|
||||
'below_threshold' => 'There are only :remaining_count seats left for this license with a minimum quantity of :min_amt. You may want to consider purchasing more seats.',
|
||||
'below_threshold_short' => 'This item is below the minimum required quantity.',
|
||||
);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
</div>
|
||||
@endcan
|
||||
|
||||
|
||||
<!-- Seats -->
|
||||
<div class="form-group {{ $errors->has('seats') ? ' has-error' : '' }}">
|
||||
<label for="seats" class="col-md-3 control-label">{{ trans('admin/licenses/form.seats') }}</label>
|
||||
|
@ -32,6 +33,7 @@
|
|||
</div>
|
||||
{!! $errors->first('seats', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span></div>') !!}
|
||||
</div>
|
||||
@include ('partials.forms.edit.minimum_quantity')
|
||||
|
||||
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
|
||||
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id',])
|
||||
|
|
|
@ -337,13 +337,23 @@
|
|||
</strong>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
|
||||
@if ($license->remaincount() <= ($license->min_amt - \App\Models\Setting::getSettings()->alert_threshold))
|
||||
<span data-tooltip="true" title="{{ trans('admin/licenses/general.below_threshold', ['remaining_count' => $license->remaincount(), 'min_amt' => $license->min_amt]) }}"><i class="fas fa-exclamation-triangle text-danger" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('general.warning') }}</span>
|
||||
</span>
|
||||
@endif
|
||||
|
||||
{{ $license->seats }}
|
||||
@if ($license->remaincount() <= ($license->min_amt - \App\Models\Setting::getSettings()->alert_threshold))
|
||||
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<strong>
|
||||
|
|
|
@ -621,6 +621,18 @@
|
|||
return frags.join(' ');
|
||||
}
|
||||
|
||||
// Show the warning if below min qty
|
||||
function minAmtFormatter(row, value) {
|
||||
|
||||
if ((row) && (row!=undefined)) {
|
||||
if (value.free_seats_count <= value.min_amt) {
|
||||
return '<span class="text-danger text-bold" data-tooltip="true" title="{{ trans('admin/licenses/general.below_threshold_short') }}">' + value.min_amt + '</span>';
|
||||
}
|
||||
return value.min_amt
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create a linked phone number in the table list
|
||||
function phoneFormatter(value) {
|
||||
|
|
Loading…
Reference in a new issue