From 88dc0700f0ee6b8f336ac9f51721da35f3e372cd Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 17 Feb 2015 17:25:30 -0800 Subject: [PATCH] Make date functions work; create negative intervals for depreciation, Also renamed "months_until_depreciation" to "time_until_depreciation" And renamed Depreciatable to Depreciable (which is an actual word in English.) Also a cleanup/consistency-enforcement for interval display. --- app/models/Asset.php | 2 +- .../{Depreciatable.php => Depreciable.php} | 19 +++++++++++++------ app/models/License.php | 2 +- app/views/backend/hardware/view.blade.php | 8 ++++---- app/views/backend/licenses/view.blade.php | 12 ++++++------ 5 files changed, 25 insertions(+), 18 deletions(-) rename app/models/{Depreciatable.php => Depreciable.php} (67%) 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