Skip to content

A free open source IT asset/license management system

Added location method, fixed assetLoc

snipece5ccc31f06a
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 9446df9996..798d4cd4c9 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -255,23 +255,33 @@ class Asset extends Depreciable
**/
public function assetLoc()
{
+ static $iterations=0;
+ static $first_asset;
if (!empty($this->assignedType())) {
- // dd($this->assignedType());
if ($this->assignedType() == self::ASSET) {
- return $this->assignedto->assetloc(); // Recurse until we have a final location
+ $iterations++;
+ if(!$first_asset) {
+ $first_asset=$this;
+ }
+ if($iterations>10) {
+ throw new \Exception("Asset assignment Loop for Asset ID: ".$first_asset->id);
+ }
+ $assigned_to=Asset::find($this->assigned_to); //have to do this this way because otherwise it errors
+ return $assigned_to->assetLoc(); // Recurse until we have a final location
}
if ($this->assignedType() == self::LOCATION) {
- return $this->assignedTo();
+ return $this->assignedTo;
}
if ($this->assignedType() == self::USER) {
- if (!$this->assignedTo) {
- return $this->defaultLoc();
+ if (!$this->assignedTo->userLoc) {
+ //this makes no sense
+ return $this->defaultLoc;
}
- return $this->assignedTo->userLoc();
+ return $this->assignedTo->userLoc;
}
}
- return $this->defaultLoc();
+ return $this->defaultLoc;
}
public function assignedType()
@@ -407,6 +417,12 @@ class Asset extends Depreciable
}
+ public function location()
+ {
+ return $this->belongsTo('\App\Models\Location', 'location_id');
+ }
+
+
/**
* Get auto-increment