@extends('layouts.app')
@section('title',($advance->exists?'Edit':'New').' Driver Advance')
@section('page_title',($advance->exists?'Edit':'New').' Driver Advance')
@section('content')
<div class="page-head"><div><h1>{{ $advance->exists?'Edit':'Record' }} Driver Advance</h1><p>The posting debits the driver-advance asset and credits the selected cash or bank account.</p></div><a class="btn btn-secondary" href="{{ $advance->exists?route('driver-advances.show',$advance):route('driver-advances.index') }}">Back</a></div>
<form method="post" action="{{ $advance->exists?route('driver-advances.update',$advance):route('driver-advances.store') }}">@csrf @if($advance->exists)@method('put')@endif
<div class="card"><div class="card-body"><div class="form-grid">
<div class="field"><label>Branch *</label><select class="control" name="branch_id" required>@foreach($branches as $branch)<option value="{{ $branch->id }}" @selected(old('branch_id',$advance->branch_id)==$branch->id)>{{ $branch->code }} - {{ $branch->name }}</option>@endforeach</select></div>
<div class="field"><label>Advance Date *</label><input class="control" type="date" name="advance_date" value="{{ old('advance_date',optional($advance->advance_date)->format('Y-m-d')) }}" required></div>
<div class="field"><label>Driver *</label><select class="control" name="driver_id" required><option value="">Select driver</option>@foreach($drivers as $driver)<option value="{{ $driver->id }}" @selected(old('driver_id',$advance->driver_id)==$driver->id)>{{ $driver->driver_code }} - {{ $driver->name }}</option>@endforeach</select></div>
<div class="field"><label>Linked Trip</label><select class="control" name="trip_id"><option value="">No trip</option>@foreach($trips as $trip)<option value="{{ $trip->id }}" @selected(old('trip_id',$advance->trip_id)==$trip->id)>{{ $trip->trip_number }}</option>@endforeach</select></div>
<div class="field"><label>Advance Type *</label><select class="control" name="advance_type" required>@foreach(['cash','bank','trip','salary'] as $type)<option value="{{ $type }}" @selected(old('advance_type',$advance->advance_type)===$type)>{{ ucfirst($type) }}</option>@endforeach</select></div>
<div class="field"><label>Amount *</label><input class="control" type="number" min="0.0001" step="0.0001" name="amount" value="{{ old('amount',$advance->amount??0) }}" required></div>
<div class="field"><label>Driver Advance Account *</label><select class="control" name="advance_account_id" required><option value="">Select asset account</option>@foreach($accounts as $account)<option value="{{ $account->id }}" @selected(old('advance_account_id',$advance->advance_account_id)==$account->id)>{{ $account->code }} - {{ $account->name }}</option>@endforeach</select></div>
<div class="field"><label>Cash / Bank Account *</label><select class="control" name="cash_bank_account_id" required><option value="">Select payment account</option>@foreach($accounts as $account)<option value="{{ $account->id }}" @selected(old('cash_bank_account_id',$advance->cash_bank_account_id)==$account->id)>{{ $account->code }} - {{ $account->name }}</option>@endforeach</select></div>
<div class="field full"><label>Description</label><textarea class="control" rows="3" name="description">{{ old('description',$advance->description) }}</textarea></div>
</div></div><div class="card-head" style="justify-content:flex-end"><button class="btn btn-primary">Save Draft</button></div></div></form>
@endsection
