Skip to content

A free open source IT asset/license management system

Helper methods to determine if the asset or thing can be checked in

snipe210fd6399a3f
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index b34d530252..e4a953a996 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -461,6 +461,17 @@ class Asset extends Depreciable
return false;
}
+ public function availableForCheckIn()
+ {
+
+ // This asset is currently assigned to anyone and is not deleted...
+ if ($this->assigned_to) {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Checks the asset out to the target
*
@@ -627,7 +638,7 @@ class Asset extends Depreciable
*/
public function components()
{
- return $this->belongsToMany('\App\Models\Component', 'components_assets', 'asset_id', 'component_id')->withPivot('id', 'assigned_qty', 'created_at');
+ return $this->belongsToMany('\App\Models\Component', 'components_assets', 'asset_id', 'component_id')->withPivot('id', 'assigned_qty', 'created_at', 'note');
}
/**
@@ -1035,7 +1046,7 @@ class Asset extends Depreciable
*/
public function licenses()
{
- return $this->belongsToMany(License::class, 'license_seats', 'asset_id', 'license_id');
+ return $this->belongsToMany(License::class, 'license_seats', 'asset_id', 'license_id')->withPivot('notes', 'created_at', 'created_by');
}
/**
@@ -1295,6 +1306,13 @@ class Asset extends Depreciable
);
}
+ public function journal()
+ {
+ return $this->assetlog()->where('action_type', '=', 'note added')
+ ->orderBy('created_at', 'desc')
+ ->withTrashed();
+ }
+
/**
* -----------------------------------------------
* BEGIN QUERY SCOPES
diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php
index 57c3f409e8..1655d32c3e 100644
--- a/app/Models/SnipeModel.php
+++ b/app/Models/SnipeModel.php
@@ -248,4 +248,17 @@ class SnipeModel extends Model
return false;
}
+
+ public function showCheckinButton($item)
+ {
+ if ((method_exists($item, 'numRemaining')) && ($item->numRemaining() <= 0)) {
+ return true;
+ }
+
+ if ((method_exists($item, 'availableForCheckIn')) && ($item->assigned_to != '') && ($item->deleted_at == '')) {
+ return true;
+ }
+
+ return false;
+ }
}