diff --git a/app/models/Asset.php b/app/models/Asset.php index 4ecb301313..071098c441 100755 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -1,6 +1,6 @@ model->belongsTo('Depreciation','depreciation_id'); + return $this->belongsTo('Depreciation','depreciation_id'); } /** @@ -28,7 +31,7 @@ class Depreciatable extends Elegant } // fraction of value left - $current_value = round(($this->months_until_depreciated() / ($this->depreciation->months)) * $this->purchase_cost, 2); + $current_value = round(($this->time_until_depreciated() / ($this->depreciation->months)) * $this->purchase_cost, 2); if ($current_value < 0) { $current_value = 0; @@ -36,15 +39,19 @@ class Depreciatable extends Elegant return $current_value; } - public function months_until_depreciated() + public function time_until_depreciated() { // @link http://www.php.net/manual/en/class.datetime.php $d1 = new DateTime(); - $d2 = new DateTime($this->depreciated_date()); + $d2 = $this->depreciated_date(); // @link http://www.php.net/manual/en/class.dateinterval.php $interval = $d1->diff($d2); - return $interval; + if(!$interval->invert) { + return $interval; + } else { + return new DateInterval("PT0S"); //null interval (zero seconds from now) + } } public function depreciated_date() diff --git a/app/models/License.php b/app/models/License.php index 2ec061404e..b977aae9d5 100755 --- a/app/models/License.php +++ b/app/models/License.php @@ -1,6 +1,6 @@
@lang('admin/hardware/form.fully_depreciated'): - {{{ $asset->months_until_depreciated()->m }}} + {{{ $asset->time_until_depreciated()->m }}} @lang('admin/hardware/form.months') - @if ($asset->months_until_depreciated()->y > 0) - , {{{ $asset->months_until_depreciated()->y }}} + @if ($asset->time_until_depreciated()->y > 0) + , {{{ $asset->time_until_depreciated()->y }}} @lang('admin/hardware/form.years') @endif - ({{{ $asset->depreciation->depreciated_date() }}}) + ({{{ $asset->depreciated_date()->format('Y-m-d') }}})
@endif diff --git a/app/views/backend/licenses/view.blade.php b/app/views/backend/licenses/view.blade.php index e126b80bf8..19536e7287 100755 --- a/app/views/backend/licenses/view.blade.php +++ b/app/views/backend/licenses/view.blade.php @@ -73,18 +73,18 @@
@lang('admin/hardware/form.depreciates_on'): - {{{ $license->depreciated_date() }}} + {{{ $license->depreciated_date()->format("Y-m-d") }}}
@lang('admin/hardware/form.fully_depreciated'): - {{{ $license->months_until_depreciated()->m }}} + @if ($license->time_until_depreciated()->y > 0) + {{{ $license->time_until_depreciated()->y }}} + @lang('admin/hardware/form.years'), + @endif + {{{ $license->time_until_depreciated()->m }}} @lang('admin/hardware/form.months') - @if ($license->months_until_depreciated()->y > 0) - , {{{ $license->months_until_depreciated()->y }}} - @lang('admin/hardware/form.years') - @endif
@endif