App\Models\Depreciable Class Reference
Inheritance diagram for App\Models\Depreciable:
App\Models\Asset App\Models\License

Public Member Functions

 depreciation ()
 Depreciation Relation, and associated helper methods. More...
 
 get_depreciation ()
 
 getDepreciatedValue ()
 
 time_until_depreciated ()
 
 depreciated_date ()
 

Detailed Description

Definition at line 7 of file Depreciable.php.

Member Function Documentation

App\Models\Depreciable::depreciated_date ( )

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 ( )

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\Depreciable::get_depreciation ( )

Definition at line 33 of file Depreciable.php.

34  {
35  return $this->depreciation;
36  }
App\Models\Depreciable::getDepreciatedValue ( )
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  }
App\Models\Depreciable::time_until_depreciated ( )

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  }

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