mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Revert back to old method name
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
3e53870b37
commit
e84ba0c7a0
|
@ -106,10 +106,10 @@ class License extends Depreciable
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $searchableRelations = [
|
protected $searchableRelations = [
|
||||||
'manufacturer' => ['name'],
|
'manufacturer' => ['name'],
|
||||||
'company' => ['name'],
|
'company' => ['name'],
|
||||||
'category' => ['name'],
|
'category' => ['name'],
|
||||||
'depreciation' => ['name'],
|
'depreciation' => ['name'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -425,7 +425,7 @@ class License extends Depreciable
|
||||||
public static function assetcount()
|
public static function assetcount()
|
||||||
{
|
{
|
||||||
return LicenseSeat::whereNull('deleted_at')
|
return LicenseSeat::whereNull('deleted_at')
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -441,8 +441,8 @@ class License extends Depreciable
|
||||||
public function totalSeatsByLicenseID()
|
public function totalSeatsByLicenseID()
|
||||||
{
|
{
|
||||||
return LicenseSeat::where('license_id', '=', $this->id)
|
return LicenseSeat::where('license_id', '=', $this->id)
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -455,29 +455,49 @@ class License extends Depreciable
|
||||||
* @since [v2.0]
|
* @since [v2.0]
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||||
*/
|
*/
|
||||||
public function seats()
|
public function licenseSeatsRelation()
|
||||||
{
|
{
|
||||||
return $this->hasMany(LicenseSeat::class)->whereNull('deleted_at')->selectRaw('license_id, count(*) as count')->groupBy('license_id');
|
return $this->hasMany(LicenseSeat::class)->whereNull('deleted_at')->selectRaw('license_id, count(*) as count')->groupBy('license_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of total available seats for this license
|
* Sets the license seat count attribute
|
||||||
* @todo - refactor all of these weird counters for licenses. The relationships are donked, yo.
|
|
||||||
*
|
*
|
||||||
* @author A. Gianotto <snipe@snipe.net>
|
* @author A. Gianotto <snipe@snipe.net>
|
||||||
* @since [v2.0]
|
* @since [v2.0]
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function availableSeats()
|
public function getLicenseSeatsCountAttribute()
|
||||||
|
{
|
||||||
|
if ($this->licenseSeatsRelation->first()) {
|
||||||
|
return $this->licenseSeatsRelation->first()->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of total available seats across all licenses
|
||||||
|
*
|
||||||
|
* @author A. Gianotto <snipe@snipe.net>
|
||||||
|
* @since [v2.0]
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function availassetcount()
|
||||||
{
|
{
|
||||||
return LicenseSeat::whereNull('assigned_to')
|
return LicenseSeat::whereNull('assigned_to')
|
||||||
->where('license_id', '=', $this->id)
|
|
||||||
->whereNull('asset_id')
|
->whereNull('asset_id')
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function availableSeats()
|
||||||
|
{
|
||||||
|
return LicenseSeat::whereNull('assigned_to')
|
||||||
|
->whereNull('asset_id')
|
||||||
|
->whereNull('deleted_at');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of total available seats for this license
|
* Returns the number of total available seats for this license
|
||||||
*
|
*
|
||||||
|
@ -487,7 +507,7 @@ class License extends Depreciable
|
||||||
*/
|
*/
|
||||||
public function availCount()
|
public function availCount()
|
||||||
{
|
{
|
||||||
return $this->seats()
|
return $this->licenseSeatsRelation()
|
||||||
->whereNull('asset_id')
|
->whereNull('asset_id')
|
||||||
->whereNull('assigned_to')
|
->whereNull('assigned_to')
|
||||||
->whereNull('deleted_at');
|
->whereNull('deleted_at');
|
||||||
|
@ -518,9 +538,9 @@ class License extends Depreciable
|
||||||
*/
|
*/
|
||||||
public function assignedCount()
|
public function assignedCount()
|
||||||
{
|
{
|
||||||
return $this->seats()->where(function ($query) {
|
return $this->licenseSeatsRelation()->where(function ($query) {
|
||||||
$query->whereNotNull('assigned_to')
|
$query->whereNotNull('assigned_to')
|
||||||
->orWhereNotNull('asset_id');
|
->orWhereNotNull('asset_id');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,13 +628,13 @@ class License extends Depreciable
|
||||||
public function freeSeat()
|
public function freeSeat()
|
||||||
{
|
{
|
||||||
return $this->licenseseats()
|
return $this->licenseseats()
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->where(function ($query) {
|
->where(function ($query) {
|
||||||
$query->whereNull('assigned_to')
|
$query->whereNull('assigned_to')
|
||||||
->whereNull('asset_id');
|
->whereNull('asset_id');
|
||||||
})
|
})
|
||||||
->orderBy('id', 'asc')
|
->orderBy('id', 'asc')
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -644,11 +664,11 @@ class License extends Depreciable
|
||||||
$days = (is_null($days)) ? 60 : $days;
|
$days = (is_null($days)) ? 60 : $days;
|
||||||
|
|
||||||
return self::whereNotNull('expiration_date')
|
return self::whereNotNull('expiration_date')
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->whereRaw(DB::raw('DATE_SUB(`expiration_date`,INTERVAL '.$days.' DAY) <= DATE(NOW()) '))
|
->whereRaw(DB::raw('DATE_SUB(`expiration_date`,INTERVAL '.$days.' DAY) <= DATE(NOW()) '))
|
||||||
->where('expiration_date', '>', date('Y-m-d'))
|
->where('expiration_date', '>', date('Y-m-d'))
|
||||||
->orderBy('expiration_date', 'ASC')
|
->orderBy('expiration_date', 'ASC')
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -692,4 +712,4 @@ class License extends Depreciable
|
||||||
return $query->leftJoin('companies as companies', 'licenses.company_id', '=', 'companies.id')->select('licenses.*')
|
return $query->leftJoin('companies as companies', 'licenses.company_id', '=', 'companies.id')->select('licenses.*')
|
||||||
->orderBy('companies.name', $order);
|
->orderBy('companies.name', $order);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue