diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index 93088bb04..0209eae39 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 78a01b4c1..87e2ddaca 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 f5a29d790..540ebaf32 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;