-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Added #17687: Add User Responsible for a maintenances. #17907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ class Maintenance extends SnipeModel implements ICompanyableChild | |
'completion_date' => 'date_format:Y-m-d|nullable|after_or_equal:start_date', | ||
'notes' => 'string|nullable', | ||
'cost' => 'numeric|nullable|gte:0|max:99999999999999999.99', | ||
'user_responsible_id' => 'nullable|integer' | ||
]; | ||
|
||
|
||
|
@@ -57,6 +58,7 @@ class Maintenance extends SnipeModel implements ICompanyableChild | |
'asset_maintenance_time', | ||
'notes', | ||
'cost', | ||
'user_responsible_id', | ||
]; | ||
|
||
use Searchable; | ||
|
@@ -87,6 +89,7 @@ class Maintenance extends SnipeModel implements ICompanyableChild | |
'asset.supplier' => ['name'], | ||
'asset.assetstatus' => ['name'], | ||
'supplier' => ['name'], | ||
'user_responsible' => ['first_name', 'last_name'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want to refer to the relationship here, no? |
||
]; | ||
|
||
public function getCompanyableParents() | ||
|
@@ -185,7 +188,15 @@ public function assetlog() | |
->orderBy('created_at', 'desc') | ||
->withTrashed(); | ||
} | ||
|
||
|
||
/** | ||
* Get the user responsible for this maintenance. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\Relation | ||
*/ | ||
public function userResponsible() { | ||
return $this->belongsTo(\App\Models\User::class, 'user_responsible_id')->withTrashed(); | ||
} | ||
|
||
/** | ||
* Get the admin who created the maintenance | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,6 +433,19 @@ public function maintenances() | |
return $this->hasMany(\App\Models\Maintenance::class, 'user_id')->withTrashed(); | ||
} | ||
|
||
/** | ||
* Establishes the user -> maintenances relationship | ||
* | ||
* This would only be used to return maintenances that this user | ||
* is responsible for. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\Relation | ||
*/ | ||
public function maintenanceCausedBy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename this to |
||
{ | ||
return $this->hasMany(\App\Models\Maintenance::class, 'user_responsible_id')->withTrashed(); | ||
} | ||
|
||
/** | ||
* Establishes the user -> accessories relationship | ||
* | ||
|
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('maintenances', function (Blueprint $table) { | ||
if (!Schema::hasColumn('maintenances', 'user_responsible_id')) { | ||
$table->integer('user_responsible_id')->nullable()->default(null); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('maintenances', function (Blueprint $table) { | ||
$table->dropColumn('user_responsible_id'); | ||
}); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want a check here to make sure the user's ID exists in the user table.