{#  Añadimos el kilometraje del vehiculo  #}

<div class="card h-10">
	<div class="card-header">
		<h4 class="text-secondary"><span class="fas fa-car"></span> Añade el vehiculo y el kilometraje</h4>
	</div>
	<div class="card-body">
		<form method="post" class="form" id="formWizard">
			<input type="hidden" name="action" value="guardarKilometraje"/>
			{{ formToken() }}
                        <div class="row g-1">
                                <div class="col-12 col-md-3">
                                        <div class="form-group">
                                                <div class="form-group">
                                                        <label class="form-label" for="matricula">Matricula</label>
                                                        <select id="list_vehiculos" name="idvehiculo" required class="form-control">
                                                                {% for vehiculo in fsc.codeModel.all('oi_vehiculos', 'id_vehiculo', 'matricula') %}
                                                                <option value="{{ vehiculo.code }}">{{ vehiculo.description }}</option>
                                                                {% endfor %}
                                                        </select>
                                                </div>
                                        </div>
                                </div>
                                <div class="col-6 col-md-2">
                                        <div class="form-group">
                                                <div class="form-group">
                                                        <label class="form-label" for="inicial">Km Inicial</label>
                                                        <input type="number" class="form-control" id="inicial" name="kminicial" required>
                                                </div>
                                        </div>
                                </div>
                                <div class="col-6 col-md-2">
                                        <div class="form-group">
                                                <div class="form-group">
                                                        <label class="form-label" for="final">Km Final</label>
                                                        <input type="number" class="form-control" name="kmfinal" id="final">
                                                </div>
                                        </div>
                                </div>
                                <div class="col-6 col-md-3">
                                        <div class="form-group">
                                                <label class="form-label" for="nick">Usuario</label>
                                                <select id="nick" name="nick" class="form-control" required>
                                                        {% for user in fsc.codeModel.all('users', 'nick', 'nick') %}
                                                                {% if user.code == fsc.user.nick %}
                                                                        <option value="{{ user.code }}" selected>{{ user.description }}</option>
                                                                {% else %}
                                                                        <option value="{{ user.code }}">{{ user.description }}</option>
                                                                {% endif %}
                                                        {% endfor %}
                                                </select>
                                        </div>
                                </div>
                        </div>
                        <div class="row g-1 mt-2">
                                <div class="col-12">
                                        <button type="submit" class="btn btn-outline-info w-100">
                                                <i class="fas fa-save"></i> Guardar
                                        </button>
                                </div>
                        </div>
                </form>
		<div>
			<button class="btn btn-phoenix-primary w-100 mt-4" type="button" data-toggle="collapse"
				data-target="#collapseExample" aria-expanded="false"
				aria-controls="collapseExample">
				<i class="fas fa-taxi" aria-hidden="true"></i> &nbsp;Actualizar Kilometrajes
			</button>
		</div>
		{# Desplegable con los kilometrajes añadidos para actualizar valores #}
		<div class="collapse mt-2" id="collapseExample">
			{% for vehiculoOrden in fsc.orden.getVehiculos() %}
				<form method="post" class="form" id="formWizard">
					<input type="hidden" name="action" value="actualizarKilometraje"/>
					{{ formToken() }}
					<input type="hidden" name="id" value="{{ vehiculoOrden.id }}"/>
                                        <div class="row g-1">
                                                <div class="col-12 col-md-3">
                                                        <div class="form-group">
                                                                <div class="form-group">
                                                                        <label class="form-label" for="matricula">Matricula</label>
                                                                        <select id="list_vehiculos" name="idvehiculo" required class="form-control">
                                                                                {% for vehiculo in fsc.codeModel.all('oi_vehiculos', 'id_vehiculo', 'matricula') %}
                                                                                {% if vehiculo.code == vehiculoOrden.idvehiculo %}
                                                                                        <option value="{{ vehiculo.code }}" selected>{{ vehiculo.description }}</option>
                                                                                {% else %}
                                                                                        <option value="{{ vehiculo.code }}">{{ vehiculo.description }}</option>
                                                                                {% endif %}
                                                                                {% endfor %}
                                                                        </select>
                                                                </div>
                                                        </div>
                                                </div>
                                                <div class="col-6 col-md-2">
                                                        <div class="form-group">
                                                                <div class="form-group">
                                                                        <label class="form-label" for="inicial">Km Inicial</label>
                                                                        <input type="number" class="form-control" id="inicial" name="kminicial" value="{{ vehiculoOrden.km_ini }}" required>
                                                                </div>
                                                        </div>
                                                </div>
                                                <div class="col-6 col-md-2">
                                                        <div class="form-group">
                                                                <div class="form-group">
                                                                        <label class="form-label" for="final">Km Final</label>
                                                                        <input type="number" class="form-control" name="kmfinal" value="{{ vehiculoOrden.km_fin }}" id="final">
                                                                </div>
                                                        </div>
                                                </div>
                                                <div class="col-6 col-md-3">
                                                        <div class="form-group">
                                                                <label class="form-label" for="nick">Usuario</label>
                                                                <select name="nick" class="form-control" required>
                                                                        {% for user in fsc.codeModel.all('users', 'nick', 'nick') %}
                                                                                {% if user.code == vehiculoOrden.nick %}
                                                                                        <option value="{{ user.code }}" selected>{{ user.description }}</option>
                                                                                {% else %}
                                                                                        <option value="{{ user.code }}">{{ user.description }}</option>
                                                                                {% endif %}
                                                                        {% endfor %}
                                                                </select>
                                                        </div>
                                                </div>
                                                <div class="col-6 col-md-2 actualizarKilometraje">
                                                        <div class="form-group">
                                                                <button type="submit" class="btn btn-outline-info btn-sm mt-4 p-2 p-md-2 pe-md-3 ps-md-3">
                                                                        <i class="fas fa-sync-alt"></i>
                                                                </button>
                                                                <button onclick="eliminarKilometraje({{vehiculoOrden.id}})" type="button" class="btn btn-outline-danger btn-sm mt-4 p-2 p-md-2 pe-md-3 ps-md-3">
                                                                        <i class="fas fa-trash"></i>
                                                                </button>
                                                        </div>
                                                </div>
                                        </div>
				</form>
			{% endfor %}
		</div>
	</div>
</div>
