Skip to content

Commit

Permalink
Fixed the depreciation report, fixes to calculate current depreciated
Browse files Browse the repository at this point in the history
value (which were only used there). Additional fixes and refactoring
around Depreciable, in terms of how assets get depreciation via models,
and licenses get depreciation directly.
  • Loading branch information
uberbrady committed Feb 18, 2015
1 parent 3ba02b6 commit 063e5c4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
5 changes: 5 additions & 0 deletions app/models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function depreciation()
{
return $this->model->belongsTo('Depreciation','depreciation_id');
}

public function get_depreciation()
{
return $this->model->depreciation;
}

/**
* Get uploads for this asset
Expand Down
33 changes: 28 additions & 5 deletions app/models/Depreciable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,47 @@ class Depreciable extends Elegant
//REQUIRES a purchase_date field
// and a purchase_cost field

//REQUIRES a get_depreciation method,
//which will return the deprecation.
//this is needed because assets get
//their depreciation from a model,
//whereas licenses have deprecations
//directly associated with them.

//assets will override the following
//two methods in order to inherit from
//their model instead of directly (like
//here)

public function depreciation()
{
return $this->belongsTo('Depreciation','depreciation_id');
}

public function get_depreciation()
{
return $this->depreciation;
}

/**
* @param $purchase_cost
* @param $purchase_date1
* @return float|int
*/

protected function getCurrentValue()
public function getDepreciatedValue()
{
if (!$this->depreciation) { // will never happen
if (!$this->get_depreciation()) { // will never happen
return $this->purchase_cost;
}

if ($this->depreciation->months <= 0) {
if ($this->get_depreciation()->months <= 0) {
return $this->purchase_cost;
}

// fraction of value left
$current_value = round(($this->time_until_depreciated() / ($this->depreciation->months)) * $this->purchase_cost, 2);
$months_remaining = $this->time_until_depreciated()->m + $this->time_until_depreciated()->y; //UGlY
$current_value = round(($months_remaining/ $this->get_depreciation()->months) * $this->purchase_cost, 2);

if ($current_value < 0) {
$current_value = 0;
Expand All @@ -52,7 +75,7 @@ public function time_until_depreciated()
public function depreciated_date()
{
$date = date_create($this->purchase_date);
date_add($date, date_interval_create_from_date_string($this->depreciation->months . ' months'));
date_add($date, date_interval_create_from_date_string($this->get_depreciation()->months . ' months'));
return $date; //date_format($date, 'Y-m-d'); //don't bake-in format, for internationalization
}
}
5 changes: 0 additions & 5 deletions app/models/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ class License extends Depreciable
'notes' => 'alpha_space|min:0',
);

public function depreciation()
{
return $this->belongsTo('Depreciation','depreciation_id');
}

/**
* Get the assigned user
*/
Expand Down
10 changes: 5 additions & 5 deletions app/views/backend/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->time_until_depreciated()->m }}}
@lang('admin/hardware/form.months')
@if ($asset->time_until_depreciated()->y > 0)
, {{{ $asset->time_until_depreciated()->y }}}
@lang('admin/hardware/form.years')
{{{ $asset->time_until_depreciated()->y }}}
@lang('admin/hardware/form.years'),
@endif
({{{ $asset->depreciated_date()->format('Y-m-d') }}})
{{{ $asset->time_until_depreciated()->m }}}
@lang('admin/hardware/form.months')
({{{ $asset->depreciated_date()->format('Y-m-d') }}})
</div>
@endif

Expand Down
4 changes: 2 additions & 2 deletions app/views/backend/reports/depreciation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
<td class="align-right">@lang('general.currency')
{{{ number_format($asset->purchase_cost) }}}</td>
<td class="align-right">@lang('general.currency')
{{{ number_format($asset->depreciate()) }}}</td>
{{{ number_format($asset->getDepreciatedValue()) }}}</td>
<td class="align-right">@lang('general.currency')
-{{{ number_format(($asset->purchase_cost - $asset->depreciate())) }}}</td>
-{{{ number_format(($asset->purchase_cost - $asset->getDepreciatedValue())) }}}</td>
@else
<td></td>
<td></td>
Expand Down

0 comments on commit 063e5c4

Please sign in to comment.