Added location method, fixed assetLoc

This commit is contained in:
snipe 2017-10-28 01:48:27 -07:00
parent c70db75de9
commit ce5ccc31f0

View file

@ -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