Inheritance diagram for App\Models\License:
App\Models\Depreciable

Public Member Functions

 company ()
 
 assignedusers ()
 Get the assigned user. More...
 
 assetlog ()
 Get asset logs for this asset. More...
 
 uploads ()
 Get uploads for this asset. More...
 
 adminuser ()
 Get admin user for this asset. More...
 
 totalSeatsByLicenseID ()
 Get total licenses. More...
 
 availcount ()
 Get the number of available seats. More...
 
 assignedcount ()
 Get the number of assigned seats. More...
 
 remaincount ()
 
 totalcount ()
 Get the total number of seats. More...
 
 licenseseats ()
 Get license seat data. More...
 
 supplier ()
 
 freeSeat ()
 
 scopeTextSearch ($query, $search)
 Query builder scope to search on text. More...
 
 depreciation ()
 Depreciation Relation, and associated helper methods. More...
 
 get_depreciation ()
 
 getDepreciatedValue ()
 
 time_until_depreciated ()
 
 depreciated_date ()
 

Static Public Member Functions

static assetcount ()
 Get total licenses. More...
 
static availassetcount ()
 Get total licenses not checked out. More...
 
static getExpiringLicenses ($days=60)
 

Public Attributes

 $timestamps = true
 

Protected Attributes

 $injectUniqueIdentifier = true
 
 $dates = ['deleted_at']
 
 $guarded = 'id'
 
 $table = 'licenses'
 
 $rules
 

Detailed Description

Definition at line 10 of file License.php.

Member Function Documentation

App\Models\License::adminuser ( )

Get admin user for this asset.

Definition at line 73 of file License.php.

74  {
75  return $this->belongsTo('\App\Models\User', 'user_id');
76  }
static App\Models\License::assetcount ( )
static

Get total licenses.

Definition at line 81 of file License.php.

82  {
83  return LicenseSeat::whereNull('deleted_at')
84  ->count();
85  }
App\Models\License::assetlog ( )

Get asset logs for this asset.

Definition at line 50 of file License.php.

51  {
52  return $this->hasMany('\App\Models\Actionlog', 'asset_id')
53  ->where('asset_type', '=', 'software')
54  ->orderBy('created_at', 'desc');
55  }
App\Models\License::assignedcount ( )

Get the number of assigned seats.

Definition at line 126 of file License.php.

127  {
128 
129  return \App\Models\LicenseSeat::where('license_id', '=', $this->id)
130  ->where(function ($query) {
131 
132  $query->whereNotNull('assigned_to')
133  ->orWhereNotNull('asset_id');
134  })
135  ->count();
136 
137 
138  }
App\Models\License::assignedusers ( )

Get the assigned user.

Definition at line 42 of file License.php.

43  {
44  return $this->belongsToMany('\App\Models\User', 'license_seats', 'assigned_to', 'license_id');
45  }
static App\Models\License::availassetcount ( )
static

Get total licenses not checked out.

Definition at line 102 of file License.php.

103  {
104  return LicenseSeat::whereNull('assigned_to')
105  ->whereNull('asset_id')
106  ->whereNull('deleted_at')
107  ->count();
108  }
App\Models\License::availcount ( )

Get the number of available seats.

Definition at line 113 of file License.php.

114  {
115  return LicenseSeat::whereNull('assigned_to')
116  ->whereNull('asset_id')
117  ->where('license_id', '=', $this->id)
118  ->whereNull('deleted_at')
119  ->count();
120  }
App\Models\License::company ( )

Definition at line 34 of file License.php.

35  {
36  return $this->belongsTo('\App\Models\Company', 'company_id');
37  }
App\Models\Depreciable::depreciated_date ( )
inherited

Definition at line 77 of file Depreciable.php.

78  {
79  $date = date_create($this->purchase_date);
80  date_add($date, date_interval_create_from_date_string($this->get_depreciation()->months . ' months'));
81  return $date; //date_format($date, 'Y-m-d'); //don't bake-in format, for internationalization
82  }
App\Models\Depreciable::depreciation ( )
inherited

Depreciation Relation, and associated helper methods.

Definition at line 28 of file Depreciable.php.

29  {
30  return $this->belongsTo('\App\Models\Depreciation', 'depreciation_id');
31  }
App\Models\License::freeSeat ( )

Definition at line 172 of file License.php.

173  {
174  $seat = LicenseSeat::where('license_id', '=', $this->id)
175  ->whereNull('deleted_at')
176  ->whereNull('assigned_to')
177  ->whereNull('asset_id')
178  ->first();
179  return $seat->id;
180  }
App\Models\Depreciable::get_depreciation ( )
inherited

Definition at line 33 of file Depreciable.php.

34  {
35  return $this->depreciation;
36  }
App\Models\Depreciable::getDepreciatedValue ( )
inherited
Returns
float|int

Definition at line 42 of file Depreciable.php.

43  {
44  if (!$this->get_depreciation()) { // will never happen
45  return $this->purchase_cost;
46  }
47 
48  if ($this->get_depreciation()->months <= 0) {
49  return $this->purchase_cost;
50  }
51 
52  // fraction of value left
53  $months_remaining = $this->time_until_depreciated()->m + 12*$this->time_until_depreciated()->y; //UGlY
54  $current_value = round(($months_remaining/ $this->get_depreciation()->months) * $this->purchase_cost, 2);
55 
56  if ($current_value < 0) {
57  $current_value = 0;
58  }
59  return $current_value;
60  }
static App\Models\License::getExpiringLicenses (   $days = 60)
static

Definition at line 182 of file License.php.

183  {
184 
185  return License::whereNotNull('expiration_date')
186  ->whereNull('deleted_at')
187  ->whereRaw(DB::raw('DATE_SUB(`expiration_date`,INTERVAL '.$days.' DAY) <= DATE(NOW()) '))
188  ->where('expiration_date', '>', date("Y-m-d"))
189  ->orderBy('expiration_date', 'ASC')
190  ->get();
191 
192  }
App\Models\License::licenseseats ( )

Get license seat data.

Definition at line 162 of file License.php.

163  {
164  return $this->hasMany('\App\Models\LicenseSeat');
165  }
App\Models\License::remaincount ( )

Definition at line 140 of file License.php.

141  {
142  $total = $this->totalSeatsByLicenseID();
143  $taken = $this->assignedcount();
144  $diff = ($total - $taken);
145  return $diff;
146  }
totalSeatsByLicenseID()
Get total licenses.
Definition: License.php:91
assignedcount()
Get the number of assigned seats.
Definition: License.php:126
App\Models\License::scopeTextSearch (   $query,
  $search 
)

Query builder scope to search on text.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$searchSearch term
Returns
Illuminate Modified query builder

Definition at line 202 of file License.php.

203  {
204 
205  return $query->where(function ($query) use ($search) {
206 
207  $query->where('name', 'LIKE', '%'.$search.'%')
208  ->orWhere('serial', 'LIKE', '%'.$search.'%')
209  ->orWhere('notes', 'LIKE', '%'.$search.'%')
210  ->orWhere('order_number', 'LIKE', '%'.$search.'%')
211  ->orWhere('purchase_date', 'LIKE', '%'.$search.'%')
212  ->orWhere('purchase_cost', 'LIKE', '%'.$search.'%');
213  });
214  }
App\Models\License::supplier ( )

Definition at line 167 of file License.php.

168  {
169  return $this->belongsTo('\App\Models\Supplier', 'supplier_id');
170  }
App\Models\Depreciable::time_until_depreciated ( )
inherited

Definition at line 62 of file Depreciable.php.

63  {
64  // @link http://www.php.net/manual/en/class.datetime.php
65  $d1 = new \DateTime();
66  $d2 = $this->depreciated_date();
67 
68  // @link http://www.php.net/manual/en/class.dateinterval.php
69  $interval = $d1->diff($d2);
70  if (!$interval->invert) {
71  return $interval;
72  } else {
73  return new \DateInterval("PT0S"); //null interval (zero seconds from now)
74  }
75  }
App\Models\License::totalcount ( )

Get the total number of seats.

Definition at line 151 of file License.php.

152  {
153  $avail = $this->availcount();
154  $taken = $this->assignedcount();
155  $diff = ($avail + $taken);
156  return $diff;
157  }
availcount()
Get the number of available seats.
Definition: License.php:113
assignedcount()
Get the number of assigned seats.
Definition: License.php:126
App\Models\License::totalSeatsByLicenseID ( )

Get total licenses.

Definition at line 91 of file License.php.

92  {
93  return LicenseSeat::where('license_id', '=', $this->id)
94  ->whereNull('deleted_at')
95  ->count();
96  }
App\Models\License::uploads ( )

Get uploads for this asset.

Definition at line 60 of file License.php.

61  {
62  return $this->hasMany('\App\Models\Actionlog', 'asset_id')
63  ->where('asset_type', '=', 'software')
64  ->where('action_type', '=', 'uploaded')
65  ->whereNotNull('filename')
66  ->orderBy('created_at', 'desc');
67  }

Member Data Documentation

App\Models\License::$dates = ['deleted_at']
protected

Definition at line 17 of file License.php.

App\Models\License::$guarded = 'id'
protected

Definition at line 21 of file License.php.

App\Models\License::$injectUniqueIdentifier = true
protected

Definition at line 14 of file License.php.

App\Models\License::$rules
protected
Initial value:
= array(
'name' => 'required|string|min:3|max:255',
'serial' => 'required|min:5',
'seats' => 'required|min:1|max:10000|integer',
'license_email' => 'email|min:0|max:120',
'license_name' => 'string|min:0|max:100',
'note' => 'string',
'notes' => 'string|min:0',
'company_id' => 'integer',
)

Definition at line 23 of file License.php.

App\Models\License::$table = 'licenses'
protected

Definition at line 22 of file License.php.

App\Models\License::$timestamps = true

Definition at line 19 of file License.php.


The documentation for this class was generated from the following file: