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.
This commit is contained in:
Brady Wetherington
2015-02-17 17:25:30 -08:00
parent 899e2bc9b6
commit 88dc0700f0
5 changed files with 25 additions and 18 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class Asset extends Depreciatable
class Asset extends Depreciable
{
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
@@ -1,14 +1,17 @@
<?php
class Depreciatable extends Elegant
class Depreciable extends Elegant
{
/**
* Depreciation Relation, and associated helper methods
*/
//REQUIRES a purchase_date field
// and a purchase_cost field
public function depreciation()
{
return $this->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()
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class License extends Depreciatable
class License extends Depreciable
{
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
+4 -4
View File
@@ -119,13 +119,13 @@
@lang('admin/hardware/form.months')
)</div>
<div class="col-md-12" style="padding-bottom: 5px;"><strong>@lang('admin/hardware/form.fully_depreciated'): </strong>
{{{ $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') }}})
</div>
@endif
+6 -6
View File
@@ -73,18 +73,18 @@
<div class="col-md-6" style="padding-bottom: 5px">
<strong>@lang('admin/hardware/form.depreciates_on'): </strong>
{{{ $license->depreciated_date() }}}
{{{ $license->depreciated_date()->format("Y-m-d") }}}
</div>
<div class="col-md-6" style="padding-bottom: 5px">
<strong>@lang('admin/hardware/form.fully_depreciated'): </strong>
{{{ $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
</div>
@endif