Skip to content

A free open source IT asset/license management system

updates transformer, api controller

Godfrey M48821f8391f0
diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php
index 93088bb04a..0209eae392 100644
--- a/app/Http/Controllers/Api/DepreciationsController.php
+++ b/app/Http/Controllers/Api/DepreciationsController.php
@@ -20,9 +20,9 @@ class DepreciationsController extends Controller
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Depreciation::class);
- $allowed_columns = ['id','name','months','depreciation_min','created_at'];
+ $allowed_columns = ['id','name','months','depreciation_min', 'depreciation_type','created_at'];
- $depreciations = Depreciation::select('id','name','months','depreciation_min','user_id','created_at','updated_at');
+ $depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','user_id','created_at','updated_at');
if ($request->filled('search')) {
$depreciations = $depreciations->TextSearch($request->input('search'));
diff --git a/app/Http/Transformers/DepreciationsTransformer.php b/app/Http/Transformers/DepreciationsTransformer.php
index 78a01b4c1e..87e2ddaca4 100644
--- a/app/Http/Transformers/DepreciationsTransformer.php
+++ b/app/Http/Transformers/DepreciationsTransformer.php
@@ -7,6 +7,7 @@ use App\Models\Depreciable;
use App\Models\Depreciation;
use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Log;
class DepreciationsTransformer
{
@@ -26,7 +27,7 @@ class DepreciationsTransformer
'id' => (int) $depreciation->id,
'name' => e($depreciation->name),
'months' => $depreciation->months.' '.trans('general.months'),
- 'depreciation_min' => $depreciation->depreciation_min,
+ 'depreciation_min' => $depreciation->depreciation_type === 'percent' ? $depreciation->depreciation_min.'%' : $depreciation->depreciation_min,
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime')
];
diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php
index f5a29d790b..540ebaf327 100644
--- a/app/Models/Depreciable.php
+++ b/app/Models/Depreciable.php
@@ -190,7 +190,7 @@ class Depreciable extends SnipeModel
}
private function calculateDepreciation(){
$depreciation_min = 0;
- if($this->get_depreciation()->depreciation_type === 'percentage') {
+ if($this->get_depreciation()->depreciation_type === 'percent') {
$depreciation_percent= $this->get_depreciation()->depreciation_min / 100;
$depreciation_min= $this->purchase_cost * $depreciation_percent;
return $depreciation_min;