@extends('layouts.app')
@section('title','Register Fixed Asset')
@section('content')
<x-ui.form-shell title="Register Fixed Asset" description="Create an asset record and post its acquisition into the accounting ledger." :breadcrumbs="[['label'=>'Dashboard','url'=>route('dashboard')],['label'=>'Fixed Assets','url'=>route('fixed-assets.index')],['label'=>'Register Asset']]">
<form method="POST" action="{{ route('fixed-assets.store') }}" class="mf-form">@csrf
<x-ui.form-section title="Asset identity" description="Core register information used to identify and locate the asset.">
<x-ui.form-grid>
<div class="mf-col-4"><label class="mf-field-label">Branch</label><select class="mf-input" name="branch_id" required><option value="">Select branch</option>@foreach($branches as $branch)<option value="{{ $branch->id }}" @selected(old('branch_id')==$branch->id)>{{ $branch->name }}</option>@endforeach</select></div>
<div class="mf-col-4"><label class="mf-field-label">Asset name</label><input class="mf-input" name="name" value="{{ old('name') }}" required placeholder="e.g. Dell Latitude Laptop"></div>
<div class="mf-col-4"><label class="mf-field-label">Category</label><input class="mf-input" name="category" value="{{ old('category') }}" required placeholder="Computer, Furniture, Vehicle..."></div>
<div class="mf-col-4"><label class="mf-field-label">Serial / registration number</label><input class="mf-input" name="serial_number" value="{{ old('serial_number') }}"></div>
<div class="mf-col-4"><label class="mf-field-label">Location</label><input class="mf-input" name="location" value="{{ old('location') }}" placeholder="Office, store room, desk..."></div>
<div class="mf-col-4"><label class="mf-field-label">Custodian</label><select class="mf-input" name="custodian_user_id"><option value="">No custodian assigned</option>@foreach($custodians as $user)<option value="{{ $user->id }}" @selected(old('custodian_user_id')==$user->id)>{{ $user->name }}</option>@endforeach</select></div>
<div class="mf-col-12"><label class="mf-field-label">Description</label><textarea class="mf-input" name="description" rows="2">{{ old('description') }}</textarea></div>
</x-ui.form-grid>
</x-ui.form-section>

<x-ui.form-section title="Acquisition & accounting" description="Existing assets are introduced against capital. New purchases reduce the selected financial account and create balanced asset accounting entries.">
<x-ui.form-grid>
<div class="mf-col-4"><label class="mf-field-label">Acquisition source</label><select class="mf-input" name="acquisition_source" required>@foreach(\App\Models\FixedAsset::ACQUISITION_SOURCES as $value=>$label)<option value="{{ $value }}" @selected(old('acquisition_source','opening')===$value)>{{ $label }}</option>@endforeach</select></div>
<div class="mf-col-4"><label class="mf-field-label">Acquisition date</label><input type="date" class="mf-input" name="acquisition_date" value="{{ old('acquisition_date',now()->toDateString()) }}" required></div>
<div class="mf-col-4"><label class="mf-field-label">Paid from account</label><select class="mf-input" name="financial_account_id"><option value="">Not applicable / opening asset</option>@foreach($accounts as $account)<option value="{{ $account->id }}" @selected(old('financial_account_id')==$account->id)>{{ $account->branch->name }} — {{ $account->name }} ({{ number_format((float)$account->current_balance,2) }})</option>@endforeach</select><p class="mf-field-help">Required only when acquisition source is Purchased From Financial Account.</p></div>
<div class="mf-col-3"><label class="mf-field-label">Acquisition cost</label><input class="mf-input" name="acquisition_cost" value="{{ old('acquisition_cost') }}" inputmode="decimal" required></div>
<div class="mf-col-3"><label class="mf-field-label">Residual value</label><input class="mf-input" name="residual_value" value="{{ old('residual_value','0.00') }}" inputmode="decimal" required></div>
<div class="mf-col-3"><label class="mf-field-label">Supplier</label><input class="mf-input" name="supplier" value="{{ old('supplier') }}"></div>
<div class="mf-col-3"><label class="mf-field-label">Purchase reference</label><input class="mf-input" name="purchase_reference" value="{{ old('purchase_reference') }}" placeholder="Invoice / receipt no."></div>
</x-ui.form-grid>
</x-ui.form-section>

<x-ui.form-section title="Depreciation & maintenance" description="Configure the depreciation basis once. Monthly depreciation is posted from the asset record and cannot be duplicated for the same month.">
<x-ui.form-grid>
<div class="mf-col-4"><label class="mf-field-label">Depreciation method</label><select class="mf-input" name="depreciation_method">@foreach(\App\Models\FixedAsset::DEPRECIATION_METHODS as $value=>$label)<option value="{{ $value }}" @selected(old('depreciation_method','straight_line')===$value)>{{ $label }}</option>@endforeach</select></div>
<div class="mf-col-4"><label class="mf-field-label">Useful life (months)</label><input type="number" min="1" max="1200" class="mf-input" name="useful_life_months" value="{{ old('useful_life_months',36) }}"></div>
<div class="mf-col-4"><label class="mf-field-label">Depreciation starts</label><input type="date" class="mf-input" name="depreciation_start_date" value="{{ old('depreciation_start_date') }}"><p class="mf-field-help">Leave blank to use acquisition date.</p></div>
<div class="mf-col-4"><label class="mf-field-label">Status</label><select class="mf-input" name="status">@foreach(\App\Models\FixedAsset::STATUSES as $value=>$label)<option value="{{ $value }}" @selected(old('status','active')===$value)>{{ $label }}</option>@endforeach</select></div>
<div class="mf-col-4"><label class="mf-field-label">Next maintenance date</label><input type="date" class="mf-input" name="next_maintenance_date" value="{{ old('next_maintenance_date') }}"></div>
<div class="mf-col-12"><label class="mf-field-label">Notes</label><textarea class="mf-input" name="notes" rows="2">{{ old('notes') }}</textarea></div>
</x-ui.form-grid>
</x-ui.form-section>
<x-ui.form-actions><a class="mf-btn" href="{{ route('fixed-assets.index') }}">Cancel</a><button class="mf-btn mf-btn-primary">Register Asset</button></x-ui.form-actions>
</form>
</x-ui.form-shell>
@endsection
