<?php

namespace App\Http\Controllers;

use App\Models\Currency;
use App\Models\FixedAsset;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class AssetController extends Controller
{
    public function index() { return view('assets.index', ['assets' => FixedAsset::latest()->paginate(15), 'currencies' => Currency::where('is_active', true)->get()]); }
    public function store(Request $request) { $data=$request->validate(['asset_code'=>['nullable','string','max:40','unique:fixed_assets,asset_code'],'name'=>['required','string','max:120'],'category'=>['nullable','string','max:80'],'acquisition_date'=>['required','date'],'acquisition_cost'=>['required','numeric','gt:0'],'accumulated_depreciation'=>['nullable','numeric','min:0'],'residual_value'=>['nullable','numeric','min:0'],'currency_code'=>['required','exists:currencies,code'],'notes'=>['nullable','string']]); $data['asset_code']=$data['asset_code'] ?: 'AST-'.strtoupper(Str::random(7)); FixedAsset::create($data); return back()->with('success', __('Fixed asset saved.')); }
}
