Merge pull request #13526 from Godmartinz/asset-model-notifs

Added threshold notifications and min qty for Asset models
This commit is contained in:
snipe 2023-09-11 17:55:34 +01:00 committed by GitHub
commit a49d3fe131
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 75 additions and 2 deletions

View file

@ -2,6 +2,8 @@
namespace App\Helpers; namespace App\Helpers;
use App\Models\Accessory; use App\Models\Accessory;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Component; use App\Models\Component;
use App\Models\Consumable; use App\Models\Consumable;
use App\Models\CustomField; use App\Models\CustomField;
@ -643,6 +645,7 @@ class Helper
$consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get(); $consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();
$accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get(); $accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get();
$components = Component::whereNotNull('min_amt')->get(); $components = Component::whereNotNull('min_amt')->get();
$asset_models = AssetModel::where('min_amt', '>', 0)->get();
$avail_consumables = 0; $avail_consumables = 0;
$items_array = []; $items_array = [];
@ -705,6 +708,28 @@ class Helper
} }
} }
foreach ($asset_models as $asset_model){
$asset = new Asset();
$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 > 0) {
$percent = number_format((($avail / $total_owned) * 100), 0);
} else {
$percent = 100;
}
$items_array[$all_count]['id'] = $asset_model->id;
$items_array[$all_count]['name'] = $asset_model->name;
$items_array[$all_count]['type'] = 'models';
$items_array[$all_count]['percent'] = $percent;
$items_array[$all_count]['remaining'] = $avail;
$items_array[$all_count]['min_amt'] = $asset_model->min_amt;
$all_count++;
}
}
return $items_array; return $items_array;
} }

View file

@ -38,6 +38,7 @@ class AssetModelsController extends Controller
'image', 'image',
'name', 'name',
'model_number', 'model_number',
'min_amt',
'eol', 'eol',
'notes', 'notes',
'created_at', 'created_at',
@ -52,6 +53,7 @@ class AssetModelsController extends Controller
'models.image', 'models.image',
'models.name', 'models.name',
'model_number', 'model_number',
'min_amt',
'eol', 'eol',
'requestable', 'requestable',
'models.notes', 'models.notes',

View file

@ -76,6 +76,7 @@ class AssetModelsController extends Controller
$model->depreciation_id = $request->input('depreciation_id'); $model->depreciation_id = $request->input('depreciation_id');
$model->name = $request->input('name'); $model->name = $request->input('name');
$model->model_number = $request->input('model_number'); $model->model_number = $request->input('model_number');
$model->min_amt = $request->input('min_amt');
$model->manufacturer_id = $request->input('manufacturer_id'); $model->manufacturer_id = $request->input('manufacturer_id');
$model->category_id = $request->input('category_id'); $model->category_id = $request->input('category_id');
$model->notes = $request->input('notes'); $model->notes = $request->input('notes');
@ -153,6 +154,7 @@ class AssetModelsController extends Controller
$model->eol = $request->input('eol'); $model->eol = $request->input('eol');
$model->name = $request->input('name'); $model->name = $request->input('name');
$model->model_number = $request->input('model_number'); $model->model_number = $request->input('model_number');
$model->min_amt = $request->input('min_amt');
$model->manufacturer_id = $request->input('manufacturer_id'); $model->manufacturer_id = $request->input('manufacturer_id');
$model->category_id = $request->input('category_id'); $model->category_id = $request->input('category_id');
$model->notes = $request->input('notes'); $model->notes = $request->input('notes');

View file

@ -68,8 +68,8 @@ class ActionlogsTransformer
} }
} }
$clean_meta = $this->changedInfo($clean_meta);
} }
$clean_meta= $this->changedInfo($clean_meta);
} }
$file_url = ''; $file_url = '';

View file

@ -47,6 +47,7 @@ class AssetModelsTransformer
] : null, ] : null,
'image' => ($assetmodel->image != '') ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null, 'image' => ($assetmodel->image != '') ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null,
'model_number' => e($assetmodel->model_number), 'model_number' => e($assetmodel->model_number),
'min_amt' => ($assetmodel->min_amt) ? (int) $assetmodel->min_amt : null,
'depreciation' => ($assetmodel->depreciation) ? [ 'depreciation' => ($assetmodel->depreciation) ? [
'id' => (int) $assetmodel->depreciation->id, 'id' => (int) $assetmodel->depreciation->id,
'name'=> e($assetmodel->depreciation->name), 'name'=> e($assetmodel->depreciation->name),

View file

@ -29,6 +29,7 @@ class AssetModel extends SnipeModel
protected $rules = [ protected $rules = [
'name' => 'required|min:1|max:255', 'name' => 'required|min:1|max:255',
'model_number' => 'max:255|nullable', 'model_number' => 'max:255|nullable',
'min_amt' => 'integer|min:0|nullable',
'category_id' => 'required|integer|exists:categories,id', 'category_id' => 'required|integer|exists:categories,id',
'manufacturer_id' => 'integer|exists:manufacturers,id|nullable', 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable',
'eol' => 'integer:min:0|max:240|nullable', 'eol' => 'integer:min:0|max:240|nullable',
@ -65,6 +66,7 @@ class AssetModel extends SnipeModel
'fieldset_id', 'fieldset_id',
'image', 'image',
'manufacturer_id', 'manufacturer_id',
'min_amt',
'model_number', 'model_number',
'name', 'name',
'notes', 'notes',

View file

@ -65,6 +65,14 @@ class AssetModelPresenter extends Presenter
'title' => trans('admin/models/table.modelnumber'), 'title' => trans('admin/models/table.modelnumber'),
'visible' => true, 'visible' => true,
], ],
[
'field' => 'min_amt',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('mail.min_QTY'),
'visible' => true,
],
[ [
'field' => 'assets_count', 'field' => 'assets_count',
'searchable' => false, 'searchable' => false,

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddMinAmtToModelsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('models', function (Blueprint $table) {
$table->integer('min_amt')->after('model_number')->default(null);;
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('models', function (Blueprint $table) {
$table->dropColumn('min_amt');
});
}
}

View file

@ -15,6 +15,7 @@
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id']) @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
@include ('partials.forms.edit.model_number') @include ('partials.forms.edit.model_number')
@include ('partials.forms.edit.depreciation') @include ('partials.forms.edit.depreciation')
@include ('partials.forms.edit.minimum_quantity')
<!-- EOL --> <!-- EOL -->