Skip to content

A free open source IT asset/license management system

Added manufacturer and model_number to components

snipe3ee76be7e373
diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php
index 561e13c9cd..8ee5b80e83 100644
--- a/app/Http/Controllers/Api/ComponentsController.php
+++ b/app/Http/Controllers/Api/ComponentsController.php
@@ -38,6 +38,7 @@ class ComponentsController extends Controller
'name',
'min_amt',
'order_number',
+ 'model_number',
'serial',
'purchase_date',
'purchase_cost',
@@ -47,7 +48,7 @@ class ComponentsController extends Controller
];
$components = Component::select('components.*')
- ->with('company', 'location', 'category', 'assets', 'supplier', 'adminuser');
+ ->with('company', 'location', 'category', 'assets', 'supplier', 'adminuser', 'manufacturer');
if ($request->filled('search')) {
$components = $components->TextSearch($request->input('search'));
@@ -69,6 +70,14 @@ class ComponentsController extends Controller
$components->where('supplier_id', '=', $request->input('supplier_id'));
}
+ if ($request->filled('manufacturer_id')) {
+ $components->where('manufacturer_id', '=', $request->input('manufacturer_id'));
+ }
+
+ if ($request->filled('model_number')) {
+ $components->where('model_number', '=', $request->input('model_number'));
+ }
+
if ($request->filled('location_id')) {
$components->where('location_id', '=', $request->input('location_id'));
}
@@ -98,6 +107,9 @@ class ComponentsController extends Controller
case 'supplier':
$components = $components->OrderSupplier($order);
break;
+ case 'manufacturer':
+ $components = $components->OrderManufacturer($order);
+ break;
case 'created_by':
$components = $components->OrderByCreatedBy($order);
break;
diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php
index f111ef6c83..f716fbbf7f 100644
--- a/app/Http/Controllers/Api/ManufacturersController.php
+++ b/app/Http/Controllers/Api/ManufacturersController.php
@@ -60,7 +60,8 @@ class ManufacturersController extends Controller
->withCount('assets as assets_count')
->withCount('licenses as licenses_count')
->withCount('consumables as consumables_count')
- ->withCount('accessories as accessories_count');
+ ->withCount('accessories as accessories_count')
+ ->withCount('components as components_count');
if ($request->input('deleted') == 'true') {
$manufacturers->onlyTrashed();
diff --git a/app/Http/Controllers/Components/ComponentsController.php b/app/Http/Controllers/Components/ComponentsController.php
index 430984767e..c4d9bcec36 100644
--- a/app/Http/Controllers/Components/ComponentsController.php
+++ b/app/Http/Controllers/Components/ComponentsController.php
@@ -73,6 +73,8 @@ class ComponentsController extends Controller
$component->name = $request->input('name');
$component->category_id = $request->input('category_id');
$component->supplier_id = $request->input('supplier_id');
+ $component->manufacturer_id = $request->input('manufacturer_id');
+ $component->model_number = $request->input('model_number');
$component->location_id = $request->input('location_id');
$component->company_id = Company::getIdForCurrentUser($request->input('company_id'));
$component->order_number = $request->input('order_number', null);
@@ -150,6 +152,8 @@ class ComponentsController extends Controller
$component->name = $request->input('name');
$component->category_id = $request->input('category_id');
$component->supplier_id = $request->input('supplier_id');
+ $component->manufacturer_id = $request->input('manufacturer_id');
+ $component->model_number = $request->input('model_number');
$component->location_id = $request->input('location_id');
$component->company_id = Company::getIdForCurrentUser($request->input('company_id'));
$component->order_number = $request->input('order_number');
diff --git a/app/Http/Transformers/ComponentsTransformer.php b/app/Http/Transformers/ComponentsTransformer.php
index 70572c9494..f98edd6e3f 100644
--- a/app/Http/Transformers/ComponentsTransformer.php
+++ b/app/Http/Transformers/ComponentsTransformer.php
@@ -38,6 +38,8 @@ class ComponentsTransformer
'name' => e($component->category->name),
] : null,
'supplier' => ($component->supplier) ? ['id' => $component->supplier->id, 'name'=> e($component->supplier->name)] : null,
+ 'manufacturer' => ($component->manufacturer) ? ['id' => $component->manufacturer->id, 'name'=> e($component->manufacturer->name)] : null,
+ 'model_number' => ($component->model_number) ? e($component->model_number) : null,
'order_number' => e($component->order_number),
'purchase_date' => Helper::getFormattedDateObject($component->purchase_date, 'date'),
'purchase_cost' => Helper::formatCurrencyOutput($component->purchase_cost),
diff --git a/app/Http/Transformers/ManufacturersTransformer.php b/app/Http/Transformers/ManufacturersTransformer.php
index e08aaa7436..d6954c1d24 100644
--- a/app/Http/Transformers/ManufacturersTransformer.php
+++ b/app/Http/Transformers/ManufacturersTransformer.php
@@ -36,6 +36,7 @@ class ManufacturersTransformer
'licenses_count' => (int) $manufacturer->licenses_count,
'consumables_count' => (int) $manufacturer->consumables_count,
'accessories_count' => (int) $manufacturer->accessories_count,
+ 'components_count' => (int) $manufacturer->components_count,
'created_by' => ($manufacturer->adminuser) ? [
'id' => (int) $manufacturer->adminuser->id,
'name'=> e($manufacturer->adminuser->present()->fullName()),
diff --git a/app/Models/Component.php b/app/Models/Component.php
index 761c76f097..fb77bf0824 100644
--- a/app/Models/Component.php
+++ b/app/Models/Component.php
@@ -38,6 +38,7 @@ class Component extends SnipeModel
'min_amt' => 'integer|min:0|nullable',
'purchase_date' => 'date_format:Y-m-d|nullable',
'purchase_cost' => 'numeric|nullable|gte:0|max:9999999999999',
+ 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable',
];
/**
@@ -60,6 +61,8 @@ class Component extends SnipeModel
'company_id',
'supplier_id',
'location_id',
+ 'manufacturer_id',
+ 'model_number',
'name',
'purchase_cost',
'purchase_date',
@@ -77,7 +80,15 @@ class Component extends SnipeModel
*
* @var array
*/
- protected $searchableAttributes = ['name', 'order_number', 'serial', 'purchase_cost', 'purchase_date', 'notes'];
+ protected $searchableAttributes = [
+ 'name',
+ 'order_number',
+ 'serial',
+ 'purchase_cost',
+ 'purchase_date',
+ 'notes',
+ 'model_number',
+ ];
/**
* The relations and their attributes that should be included when searching the model.
@@ -89,6 +100,7 @@ class Component extends SnipeModel
'company' => ['name'],
'location' => ['name'],
'supplier' => ['name'],
+ 'manufacturer' => ['name'],
];
@@ -183,6 +195,19 @@ class Component extends SnipeModel
return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id');
}
+
+ /**
+ * Establishes the item -> manufacturer relationship
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v3.0]
+ * @return \Illuminate\Database\Eloquent\Relations\Relation
+ */
+ public function manufacturer()
+ {
+ return $this->belongsTo(\App\Models\Manufacturer::class, 'manufacturer_id');
+ }
+
/**
* Establishes the component -> action logs relationship
*
@@ -311,6 +336,19 @@ class Component extends SnipeModel
return $query->leftJoin('suppliers', 'components.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order);
}
+ /**
+ * Query builder scope to order on manufacturer
+ *
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ *
+ * @return \Illuminate\Database\Query\Builder Modified query builder
+ */
+ public function scopeOrderManufacturer($query, $order)
+ {
+ return $query->leftJoin('manufacturers', 'components.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);
+ }
+
public function scopeOrderByCreatedBy($query, $order)
{
return $query->leftJoin('users as admin_sort', 'components.created_by', '=', 'admin_sort.id')->select('components.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php
index 6e72b3a2bb..1b31f496d3 100755
--- a/app/Models/Manufacturer.php
+++ b/app/Models/Manufacturer.php
@@ -78,6 +78,7 @@ class Manufacturer extends SnipeModel
&& (($this->licenses_count ?? $this->licenses()->count()) === 0)
&& (($this->consumables_count ?? $this->consumables()->count()) === 0)
&& (($this->accessories_count ?? $this->accessories()->count()) === 0)
+ && (($this->components_count ?? $this->components()->count()) === 0)
&& ($this->deleted_at == '');
}
@@ -106,6 +107,10 @@ class Manufacturer extends SnipeModel
return $this->hasMany(\App\Models\Consumable::class, 'manufacturer_id');
}
+ public function components()
+ {
+ return $this->hasMany(\App\Models\Component::class, 'manufacturer_id');
+ }
public function adminuser()
{
diff --git a/app/Presenters/ComponentPresenter.php b/app/Presenters/ComponentPresenter.php
index f32bb56d57..39a177592d 100644
--- a/app/Presenters/ComponentPresenter.php
+++ b/app/Presenters/ComponentPresenter.php
@@ -66,8 +66,20 @@ class ComponentPresenter extends Presenter
'title' => trans('general.supplier'),
'visible' => false,
'formatter' => 'suppliersLinkObjFormatter',
- ],
- [
+ ], [
+ 'field' => 'model_number',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'title' => trans('admin/models/table.modelnumber'),
+ ], [
+ 'field' => 'manufacturer',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.manufacturer'),
+ 'visible' => false,
+ 'formatter' => 'manufacturersLinkObjFormatter',
+ ], [
'field' => 'qty',
'searchable' => false,
'sortable' => true,
diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.php
index ea29974f34..dfefec2998 100644
--- a/app/Presenters/ManufacturerPresenter.php
+++ b/app/Presenters/ManufacturerPresenter.php
@@ -124,8 +124,15 @@ class ManufacturerPresenter extends Presenter
'title' => trans('general.accessories'),
'visible' => true,
'class' => 'css-accessory',
- ],
- [
+ ], [
+ 'field' => 'components_count',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.components'),
+ 'visible' => true,
+ 'class' => 'css-component',
+ ], [
'field' => 'created_by',
'searchable' => false,
'sortable' => true,
diff --git a/database/migrations/2024_10_23_162301_add_manufacturer_id_model_number_to_consumables.php b/database/migrations/2024_10_23_162301_add_manufacturer_id_model_number_to_consumables.php
new file mode 100644
index 0000000000..0180ac0edd
--- /dev/null
+++ b/database/migrations/2024_10_23_162301_add_manufacturer_id_model_number_to_consumables.php
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('components', function (Blueprint $table) {
+ $table->integer('manufacturer_id')->after('purchase_cost')->nullable()->default(null);
+ $table->string('model_number')->after('purchase_cost')->nullable()->default(null);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('components', function (Blueprint $table) {
+ $table->dropColumn('manufacturer_id');
+ $table->dropColumn('model_number');
+ });
+ }
+};
diff --git a/resources/views/components/edit.blade.php b/resources/views/components/edit.blade.php
index ce77b5130d..206418f894 100644
--- a/resources/views/components/edit.blade.php
+++ b/resources/views/components/edit.blade.php
@@ -20,6 +20,8 @@
@include ('partials.forms.edit.quantity')
@include ('partials.forms.edit.minimum_quantity')
@include ('partials.forms.edit.serial', ['fieldname' => 'serial'])
+@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
+@include ('partials.forms.edit.model_number')
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
diff --git a/resources/views/manufacturers/view.blade.php b/resources/views/manufacturers/view.blade.php
index 49e151e459..e900a1b010 100644
--- a/resources/views/manufacturers/view.blade.php
+++ b/resources/views/manufacturers/view.blade.php
@@ -79,6 +79,19 @@
{{ trans('general.consumables') }}
{!! ($manufacturer->consumables->count() > 0 ) ? '<badge class="badge badge-secondary">'.number_format($manufacturer->consumables->count()).'</badge>' : '' !!}
</span>
+ </a>
+ </li>
+
+ <li>
+ <a href="#components" data-toggle="tab">
+
+ <span class="hidden-lg hidden-md">
+ <x-icon type="components" class="fa-2x" />
+ </span>
+ <span class="hidden-xs hidden-sm">
+ {{ trans('general.components') }}
+ {!! ($manufacturer->components->count() > 0 ) ? '<badge class="badge badge-secondary">'.number_format($manufacturer->components->count()).'</badge>' : '' !!}
+ </span>
</a>
</li>
@@ -186,12 +199,35 @@
class="table table-striped snipe-table"
data-url="{{ route('api.consumables.index', ['manufacturer_id' => $manufacturer->id]) }}"
data-export-options='{
- "fileName": "export-manufacturers-{{ str_slug($manufacturer->name) }}-consumabled-{{ date('Y-m-d') }}",
+ "fileName": "export-manufacturers-{{ str_slug($manufacturer->name) }}-consumables-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
</table>
+ </div> <!-- /.tab-pan consumables-->
+
+ <div class="tab-pane fade" id="components">
+ <table
+ data-columns="{{ \App\Presenters\ComponentPresenter::dataTableLayout() }}"
+ data-cookie-id-table="componentsTable"
+ data-pagination="true"
+ data-id-table="componentsTable"
+ data-search="true"
+ data-show-footer="true"
+ data-side-pagination="server"
+ data-show-columns="true"
+ data-show-export="true"
+ data-show-refresh="true"
+ data-sort-order="asc"
+ id="componentsTable"
+ class="table table-striped snipe-table"
+ data-url="{{ route('api.components.index', ['manufacturer_id' => $manufacturer->id]) }}"
+ data-export-options='{
+ "fileName": "export-manufacturers-{{ str_slug($manufacturer->name) }}-components-{{ date('Y-m-d') }}",
+ "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
+ }'>
+ </table>
</div> <!-- /.tab-pan consumables-->