updates transformer, api controller

This commit is contained in:
Godfrey M 2024-07-16 12:58:23 -07:00
parent aaa2858337
commit 48821f8391
3 changed files with 5 additions and 4 deletions

View file

@ -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'));

View file

@ -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')
];

View file

@ -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;