@extends('layouts.app')
@section('title',($job->exists?'Edit':'New').' Job')
@section('page_title',($job->exists?'Edit':'New').' Transport Job')
@section('content')
<div class="page-head"><div><h1>{{ $job->exists?'Edit':'Create' }} Transport Job</h1><p>Rates may be estimated here; actual profit is derived from trips, charges and costs.</p></div><a class="btn btn-secondary" href="{{ $job->exists?route('jobs.show',$job):route('jobs.index') }}">Back</a></div>
<form method="post" action="{{ $job->exists?route('jobs.update',$job):route('jobs.store') }}">@csrf @if($job->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 $b)<option value="{{ $b->id }}" @selected(old('branch_id',$job->branch_id)==$b->id)>{{ $b->code }} - {{ $b->name }}</option>@endforeach</select></div>
<div class="field"><label>Customer *</label><select class="control" name="customer_id" required><option value="">Select customer</option>@foreach($customers as $p)<option value="{{ $p->id }}" @selected(old('customer_id',$job->customer_id)==$p->id)>{{ $p->legal_name }}</option>@endforeach</select></div>
<div class="field"><label>Job Date *</label><input class="control" type="date" name="job_date" value="{{ old('job_date',optional($job->job_date)->format('Y-m-d')) }}" required></div><div class="field"><label>Requested Date</label><input class="control" type="date" name="requested_date" value="{{ old('requested_date',optional($job->requested_date)->format('Y-m-d')) }}"></div>
<div class="field"><label>Contract</label><select class="control" name="contract_id"><option value="">None</option>@foreach($contracts as $c)<option value="{{ $c->id }}" @selected(old('contract_id',$job->contract_id)==$c->id)>{{ $c->contract_number }} - {{ $c->title }}</option>@endforeach</select></div><div class="field"><label>Customer PO</label><input class="control" name="customer_po" value="{{ old('customer_po',$job->customer_po) }}"></div>
<div class="field"><label>Service Type</label><select class="control" name="service_type_id"><option value="">Select</option>@foreach($services as $s)<option value="{{ $s->id }}" @selected(old('service_type_id',$job->service_type_id)==$s->id)>{{ $s->code }} - {{ $s->name }}</option>@endforeach</select></div><div class="field"><label>Route</label><select class="control" name="route_id"><option value="">Custom route</option>@foreach($routes as $r)<option value="{{ $r->id }}" @selected(old('route_id',$job->route_id)==$r->id)>{{ $r->name }} ({{ $r->origin }} → {{ $r->destination }})</option>@endforeach</select></div>
<div class="field"><label>Pickup Location</label><input class="control" name="pickup_location" value="{{ old('pickup_location',$job->pickup_location) }}"></div><div class="field"><label>Delivery Location</label><input class="control" name="delivery_location" value="{{ old('delivery_location',$job->delivery_location) }}"></div>
<div class="field full"><label>Cargo Description</label><textarea class="control" name="cargo_description">{{ old('cargo_description',$job->cargo_description) }}</textarea></div>
<div class="field"><label>Quantity</label><input class="control" type="number" step="0.0001" name="quantity" value="{{ old('quantity',$job->quantity??1) }}"></div><div class="field"><label>Trips Planned</label><input class="control" type="number" min="1" name="number_of_trips" value="{{ old('number_of_trips',$job->number_of_trips??1) }}"></div>
<div class="field"><label>Weight</label><input class="control" type="number" step="0.0001" name="weight" value="{{ old('weight',$job->weight) }}"></div><div class="field"><label>Volume</label><input class="control" type="number" step="0.0001" name="volume" value="{{ old('volume',$job->volume) }}"></div>
<div class="field"><label>Vehicle Type</label><input class="control" name="vehicle_type" value="{{ old('vehicle_type',$job->vehicle_type) }}"></div><div class="field"><label>Assigned Staff</label><select class="control" name="assigned_user_id"><option value="">Unassigned</option>@foreach($users as $u)<option value="{{ $u->id }}" @selected(old('assigned_user_id',$job->assigned_user_id)==$u->id)>{{ $u->name }}</option>@endforeach</select></div>
<div class="field"><label>Estimated Revenue</label><input class="control" type="number" step="0.01" name="estimated_revenue" value="{{ old('estimated_revenue',$job->estimated_revenue??0) }}"></div><div class="field"><label>Estimated Cost</label><input class="control" type="number" step="0.01" name="estimated_cost" value="{{ old('estimated_cost',$job->estimated_cost??0) }}"></div>
<div class="field"><label>VAT Code</label><select class="control" name="tax_code_id"><option value="">Review later</option>@foreach($taxCodes as $t)<option value="{{ $t->id }}" @selected(old('tax_code_id',$job->tax_code_id)==$t->id)>{{ $t->code }} - {{ $t->name }}</option>@endforeach</select></div><div class="field"><label>Status</label><select class="control" name="status">@foreach(['enquiry','quotation','confirmed','scheduled','vehicle_assigned','driver_assigned','in_transit','reached_destination','delivered','pod_received','ready_to_invoice','invoiced','closed','cancelled'] as $s)<option value="{{ $s }}" @selected(old('status',$job->status)===$s)>{{ ucwords(str_replace('_',' ',$s)) }}</option>@endforeach</select></div>
<div class="field"><label>Delivery Status</label><select class="control" name="delivery_status">@foreach(['pending','in_transit','delivered','failed','cancelled'] as $s)<option value="{{ $s }}" @selected(old('delivery_status',$job->delivery_status)===$s)>{{ ucwords(str_replace('_',' ',$s)) }}</option>@endforeach</select></div><div class="field"><label>Billing Status</label><select class="control" name="billing_status">@foreach(['not_invoiced','partially_invoiced','invoiced'] as $s)<option value="{{ $s }}" @selected(old('billing_status',$job->billing_status)===$s)>{{ ucwords(str_replace('_',' ',$s)) }}</option>@endforeach</select></div>
<input type="hidden" name="vendor_billing_status" value="{{ old('vendor_billing_status',$job->vendor_billing_status??'not_billed') }}">
<div class="field"><label>Internal Notes</label><textarea class="control" name="internal_notes">{{ old('internal_notes',$job->internal_notes) }}</textarea></div><div class="field"><label>Customer Notes</label><textarea class="control" name="customer_notes">{{ old('customer_notes',$job->customer_notes) }}</textarea></div>
</div></div><div class="card-head" style="justify-content:flex-end"><a class="btn btn-secondary" href="{{ route('jobs.index') }}">Cancel</a><button class="btn btn-primary">Save Job</button></div></div></form>
@endsection
