-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added manufacturer and model_number to components
Signed-off-by: snipe <[email protected]>
- Loading branch information
Showing
12 changed files
with
158 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 @@ public function supplier() | |
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 @@ public function scopeOrderSupplier($query, $order) | |
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
database/migrations/2024_10_23_162301_add_manufacturer_id_model_number_to_consumables.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters