@extends('layouts.app')
@section('title',($trip->exists?'Edit':'New').' Trip')
@section('page_title',($trip->exists?'Edit':'New').' Trip')
@section('content')
<div class="page-head"><div><h1>{{ $trip->exists?'Edit':'Create' }} Trip</h1><p>Assign own or hired transport and record customer/vendor rates separately.</p></div><a class="btn btn-secondary" href="{{ $trip->exists?route('trips.show',$trip):route('trips.index') }}">Back</a></div>
<form method="post" action="{{ $trip->exists?route('trips.update',$trip):route('trips.store') }}">@csrf @if($trip->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">@foreach($branches as $b)<option value="{{ $b->id }}" @selected(old('branch_id',$trip->branch_id)==$b->id)>{{ $b->code }} - {{ $b->name }}</option>@endforeach</select></div><div class="field"><label>Transport Job *</label><select class="control" name="transport_job_id" required>@foreach($jobs as $j)<option value="{{ $j->id }}" @selected(old('transport_job_id',$trip->transport_job_id)==$j->id)>{{ $j->job_number }} - {{ $j->customer?->legal_name }}</option>@endforeach</select></div>
<div class="field"><label>Vehicle</label><select class="control" name="vehicle_id"><option value="">External / unassigned</option>@foreach($vehicles as $v)<option value="{{ $v->id }}" @selected(old('vehicle_id',$trip->vehicle_id)==$v->id)>{{ $v->plate_number }} - {{ $v->vehicle_type }}</option>@endforeach</select></div><div class="field"><label>Driver</label><select class="control" name="driver_id"><option value="">Unassigned</option>@foreach($drivers as $d)<option value="{{ $d->id }}" @selected(old('driver_id',$trip->driver_id)==$d->id)>{{ $d->name }} ({{ $d->driver_code }})</option>@endforeach</select></div>
<div class="field"><label>Subcontractor / Vendor</label><select class="control" name="vendor_id"><option value="">Own vehicle</option>@foreach($vendors as $v)<option value="{{ $v->id }}" @selected(old('vendor_id',$trip->vendor_id)==$v->id)>{{ $v->legal_name }}</option>@endforeach</select></div><div class="field"><label>Status</label><select class="control" name="status">@foreach(['scheduled','vehicle_assigned','driver_assigned','in_transit','reached_destination','delivered','cancelled'] as $s)<option value="{{ $s }}" @selected(old('status',$trip->status)===$s)>{{ ucwords(str_replace('_',' ',$s)) }}</option>@endforeach</select></div>
<div class="field"><label>Pickup Date & Time</label><input class="control" type="datetime-local" name="pickup_at" value="{{ old('pickup_at',optional($trip->pickup_at)->format('Y-m-d\TH:i')) }}"></div><div class="field"><label>Delivery Date & Time</label><input class="control" type="datetime-local" name="delivery_at" value="{{ old('delivery_at',optional($trip->delivery_at)->format('Y-m-d\TH:i')) }}"></div>
<div class="field"><label>Pickup Location</label><input class="control" name="pickup_location" value="{{ old('pickup_location',$trip->pickup_location) }}"></div><div class="field"><label>Delivery Location</label><input class="control" name="delivery_location" value="{{ old('delivery_location',$trip->delivery_location) }}"></div>
<div class="field"><label>Customer Rate</label><input class="control" type="number" step="0.01" name="customer_rate" value="{{ old('customer_rate',$trip->customer_rate??0) }}"></div><div class="field"><label>Vendor Rate</label><input class="control" type="number" step="0.01" name="vendor_rate" value="{{ old('vendor_rate',$trip->vendor_rate??0) }}"></div>
<div class="field"><label>Additional Revenue</label><input class="control" type="number" step="0.01" name="additional_revenue" value="{{ old('additional_revenue',$trip->additional_revenue??0) }}"></div><div class="field"><label>Additional Cost</label><input class="control" type="number" step="0.01" name="additional_cost" value="{{ old('additional_cost',$trip->additional_cost??0) }}"></div>
<div class="field"><label>Start Odometer</label><input class="control" type="number" step="0.01" name="start_odometer" value="{{ old('start_odometer',$trip->start_odometer) }}"></div><div class="field"><label>End Odometer</label><input class="control" type="number" step="0.01" name="end_odometer" value="{{ old('end_odometer',$trip->end_odometer) }}"></div>
<div class="field full"><label>Notes</label><textarea class="control" name="notes">{{ old('notes',$trip->notes) }}</textarea></div></div></div><div class="card-head" style="justify-content:flex-end"><button class="btn btn-primary">Save Trip</button></div></div></form>
@endsection
