mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add location/user tracking to maintenances
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
b1cd44341b
commit
dc7bdca378
|
@ -76,6 +76,8 @@ class AssetMaintenancesController extends Controller
|
|||
'supplier',
|
||||
'is_warranty',
|
||||
'status_label',
|
||||
'assigned_to',
|
||||
'assigned_type',
|
||||
];
|
||||
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
|
|
@ -117,15 +117,26 @@ class AssetMaintenancesController extends Controller
|
|||
$assetMaintenance->completion_date = $request->input('completion_date');
|
||||
$assetMaintenance->user_id = Auth::id();
|
||||
|
||||
if (($assetMaintenance->completion_date !== null)
|
||||
&& ($assetMaintenance->start_date !== '')
|
||||
&& ($assetMaintenance->start_date !== '0000-00-00')
|
||||
) {
|
||||
$startDate = Carbon::parse($assetMaintenance->start_date);
|
||||
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
||||
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
||||
// This asset is checked out - let's see to whom
|
||||
if ($asset->assigned_to) {
|
||||
|
||||
$assetMaintenance->assigned_to = $asset->assigned_to;
|
||||
if ($asset->assignedType() == 'asset') {
|
||||
$assetMaintenance->assigned_type = \App\Models\Asset::class;
|
||||
} elseif ($asset->assignedType() == 'location') {
|
||||
$assetMaintenance->assigned_type = \App\Models\Location::class;
|
||||
} else {
|
||||
$assetMaintenance->assigned_type = \App\Models\User::class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$startDate = Carbon::parse($assetMaintenance->start_date);
|
||||
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
||||
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
||||
|
||||
|
||||
// Was the asset maintenance created?
|
||||
if ($assetMaintenance->save()) {
|
||||
// Redirect to the new asset maintenance page
|
||||
|
|
|
@ -57,6 +57,11 @@ class AssetMaintenancesTransformer
|
|||
'id' => (int) $assetmaintenance->asset->defaultLoc->id,
|
||||
'name'=> e($assetmaintenance->asset->defaultLoc->name),
|
||||
] : null,
|
||||
'assigned_to' => (($assetmaintenance->asset) && ($assetmaintenance->asset->defaultLoc)) ? [
|
||||
'id' => (int) $assetmaintenance->asset->defaultLoc->id,
|
||||
'type'=> e($assetmaintenance->asset->defaultLoc->name),
|
||||
'name'=> e($assetmaintenance->asset->defaultLoc->name),
|
||||
] : null,
|
||||
'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedownInline($assetmaintenance->notes) : null,
|
||||
'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id, 'name'=> e($assetmaintenance->supplier->name)] : null,
|
||||
'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
|
||||
|
|
|
@ -53,6 +53,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
|||
'asset_maintenance_time',
|
||||
'notes',
|
||||
'cost',
|
||||
'assigned_type',
|
||||
'assigned_to',
|
||||
];
|
||||
|
||||
use Searchable;
|
||||
|
|
|
@ -239,6 +239,21 @@ class Location extends SnipeModel
|
|||
->with('children');
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the location -> maintenances relationship
|
||||
*
|
||||
* This would only be used to return maintenances that this user
|
||||
* created.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.3.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetmaintenances()
|
||||
{
|
||||
return $this->hasMany(\App\Models\AssetMaintenance::class, 'assigned_to')->where('assigned_type', 'App\Models\Location')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the asset -> location assignment relationship
|
||||
*
|
||||
|
|
|
@ -299,6 +299,21 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
|||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetmaintenances()
|
||||
{
|
||||
return $this->hasMany(\App\Models\AssetMaintenance::class, 'assigned_to')->where('assigned_type', 'App\Models\User')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the user -> maintenances relationship
|
||||
*
|
||||
* This would only be used to return maintenances that this user
|
||||
* created.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.3.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function admin()
|
||||
{
|
||||
return $this->hasMany(\App\Models\AssetMaintenance::class, 'user_id')->withTrashed();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddUserLocationToMaintenances extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('asset_maintenances', function (Blueprint $table) {
|
||||
$table->string('assigned_type')->nullable()->default(null);
|
||||
$table->integer('assigned_to')->nullable()->default(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('asset_maintenances', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('asset_maintenances', 'assigned_type')) {
|
||||
$table->dropColumn('assigned_type');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('assigned_to', 'assigned_to')) {
|
||||
$table->dropColumn('assigned_to');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue