<!-- $o = Supplier::class -->
<div class="row">
	<div class="col-4">
		<div class="form-group has-validation">
			<label for="cost_id">Supplier Invoice</label>
			<select class="form-control form-control-border" id="cost_id" name="cost_id">
				<option value=""></option>
				<option value="">Add New</option>
				@foreach(\App\Models\Cost::where('supplier_id',$o->id)->orderBy('billed_at','DESC')->get() as $oo)
					<option value="{{ $oo->id }}">{{ $oo->billed_at->format('Y-m-d') }}: ${{ number_format($oo->total,2) }}</option>
				@endforeach
			</select>
			<span class="invalid-feedback" role="alert">
				@error('name')
					{{ $message }}
				@else
					Date is required.
				@enderror
			</span>
			<span class="input-helper">Suppliers Invoice</span>
		</div>
	</div>
</div>

@section('page-scripts')
	<script type="text/javascript">
		$(document).ready(function() {
			$('#cost_id')
				.on('change',function(item) {
					window.location.href = '{{ url('a/supplier/cost') }}/'+(item.target.value ? item.target.value : 'new/'+{{ $o->id }});
				});
		});
	</script>
@append