@extends('layouts.app')
@section('title','New Virement')
@section('crumbs','<a href="'.route('budget-virements.index').'">Budget Virements</a> · <b>New</b>')
@section('content')
<div class="card" style="max-width:720px"><div class="card-h"><h2>New virement <small class="muted">{{ $docNo }}</small></h2></div>
<div class="card-b">
@if($errors->any())<div class="flash err">✕ {{ $errors->first() }}</div>@endif
<form method="GET" action="{{ route('budget-virements.create') }}">
<div class="frow"><div class="fld c6"><label>Budget</label>
<select name="budget_id" onchange="this.form.submit()">
@foreach($budgets as $b)<option value="{{ $b->id }}" {{ $budgetId==$b->id?'selected':'' }}>{{ $b->name }} ({{ $b->fiscalYear->name ?? '' }} · {{ $b->status }})</option>@endforeach
</select></div></div>
</form>
<form method="POST" action="{{ route('budget-virements.store') }}">@csrf
<div class="frow">
<div class="fld c6"><label>From line</label>
<select name="from_budget_line_id" required>
@foreach($lines as $l)<option value="{{ $l->id }}">{{ $l->account->display_name ?? 'Acc #'.$l->account_id }} — M{{ $l->month }} · avail {{ money(\App\Services\VirementService::available($l)) }}</option>@endforeach
</select></div>
<div class="fld c6"><label>To line</label>
<select name="to_budget_line_id" required>
@foreach($lines as $l)<option value="{{ $l->id }}">{{ $l->account->display_name ?? 'Acc #'.$l->account_id }} — M{{ $l->month }} · avail {{ money(\App\Services\VirementService::available($l)) }}</option>@endforeach
</select></div>
<div class="fld c4"><label>Amount</label><input type="number" step="0.01" min="0.01" name="amount" value="{{ old('amount') }}" required></div>
<div class="fld c8"><label>Reason</label><input type="text" name="reason" value="{{ old('reason') }}" required maxlength="500" placeholder="Why are funds being moved?"></div>
</div>
<div style="margin-top:12px;display:flex;gap:8px">
<button class="btn">Submit for approval</button>
<a class="btn btn-ghost" href="{{ route('budget-virements.index') }}">Cancel</a>
</div>
</form>
<p class="muted" style="margin-top:8px">Lines move within one budget only. The transfer posts when Finance approves (available funds re-checked at posting).</p>
</div></div>
@endsection
