fixes current value and monthly depreciation on reports and calculations
This commit is contained in:
parent
a0624fe179
commit
6b6a079440
2 changed files with 20 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Transformers;
|
namespace App\Http\Transformers;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
use App\Models\Depreciable;
|
||||||
use App\Models\Depreciation;
|
use App\Models\Depreciation;
|
||||||
use Gate;
|
use Gate;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
@ -19,13 +20,14 @@ class DepreciationsTransformer
|
||||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transformDepreciation(Depreciation $depreciation)
|
public function transformDepreciation(Depreciation $depreciation, Depreciable $monthly_depreciation)
|
||||||
{
|
{
|
||||||
$array = [
|
$array = [
|
||||||
'id' => (int) $depreciation->id,
|
'id' => (int) $depreciation->id,
|
||||||
'name' => e($depreciation->name),
|
'name' => e($depreciation->name),
|
||||||
'months' => $depreciation->months.' '.trans('general.months'),
|
'months' => $depreciation->months.' '.trans('general.months'),
|
||||||
'depreciation_min' => $depreciation->depreciation_min,
|
'depreciation_min' => $depreciation->depreciation_min,
|
||||||
|
'monthly_depreciation' => $monthly_depreciation->getMonthlyDepreciation(),
|
||||||
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
|
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
|
||||||
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime')
|
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime')
|
||||||
];
|
];
|
||||||
|
|
|
@ -70,20 +70,31 @@ class Depreciable extends SnipeModel
|
||||||
{
|
{
|
||||||
$months_passed = $this->purchase_date->diff(now())->m;
|
$months_passed = $this->purchase_date->diff(now())->m;
|
||||||
|
|
||||||
// The equation here is (Purchase_Cost-Floor_min)*(Months_passed/Months_til_depreciated)
|
if($months_passed >= $this->get_depreciation()->months){
|
||||||
$current_value= round((($this->purchase_cost-$this->get_depreciation()->depreciation_min)*($months_passed/$this->get_depreciation()->months)),2);
|
//if there is a floor use it
|
||||||
|
if($this->get_depreciation()->deprecation_min->isNotEmpty()) {
|
||||||
|
|
||||||
if($this->get_depreciation()->depreciation_min > $current_value) {
|
$current_value = $this->get_depreciation()->depreciation_min;
|
||||||
|
|
||||||
$current_value=round($this->get_depreciation()->depreciation_min,2);
|
}else{
|
||||||
|
$current_value = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($current_value < 0) {
|
else {
|
||||||
$current_value = 0;
|
// The equation here is (Purchase_Cost-Floor_min)*(Months_passed/Months_til_depreciated)
|
||||||
|
$current_value = round(($this->purchase_cost-($this->purchase_cost - ($this->get_depreciation()->depreciation_min)) * ($months_passed / $this->get_depreciation()->months)), 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $current_value;
|
return $current_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMonthlyDepreciation(){
|
||||||
|
|
||||||
|
return ($this->purchase_cost-$this->get_depreciation()->depreciation_min)/$this->get_depreciation()->months;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param onlyHalfFirstYear Boolean always applied only second half of the first year
|
* @param onlyHalfFirstYear Boolean always applied only second half of the first year
|
||||||
* @return float|int
|
* @return float|int
|
||||||
|
|
Loading…
Add table
Reference in a new issue