<?php       
function lista_vehiculos($mysqli){
    ?>	
    <div class="page-title-box d-flex align-items-center justify-content-between">
		<h4 class="mb-0">Vehículos</h4>
		<div class="page-title-right">
			<ol class="breadcrumb m-0">
				<li class="breadcrumb-item"><a href="<?_GetDomain?>index.php">Escritorio</a></li>
				<li class="breadcrumb-item active">Vehículos</li>
			</ol>
		</div>
	</div>
    <div class="content-body">
        <div class="row">
            <div class="col-12">
                <div class="card">						
                    <div class="card-content">
                        <div class="card-body card-dashboard">
                            <table width="100%" border="0">
                            <tr>
                                <td><p class="card-text">Información de vehículos</p></td>
                                <td align="right"><a href="formulario.php?p=1&id=0" class="btn btn-info" style="padding:3px" title="Editar"> + Agregar</a> </td>
                            </tr>
                            </table>

                        </div>
                        <div class="table-responsive">
                            <table class="table table-bordered mb-0">
                                <thead>
                                    <tr>			
										<th width="15%">Imagen</th>									
                                        <th width="30%">Vehículo</th>
                                        <th width="20%">Modelo</th>
                                        <th width="10%">Año</th>
										<th width="10%">carga</th>
										<th width="10%">Valor por día</th>                                        																																
                                        <th width="5%">Acción</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php
                                $i=1;
                                
								$rs = getAllVehiculos($mysqli);
								while ($rows = $rs->fetch_assoc()){
								    $id_vehiculo = $rows['id_vehiculo'];
									$nombre = $rows['nombre'];
									$color = $rows['color'];
									$modelo = $rows['modelo'];
									$ano = $rows['ano'];
									$carga = $rows['carga'];
									$valor_dia = $rows['valor_dia'];
									$foto1 = $rows['foto1'];
									?>
                                    <tr>                                        
                                        <td><img src="prod/<?=$foto1?>" width="100px"></td>
                                        <td><?=$nombre?></td>
                                        <td><?=$modelo?></td>
                                        <td><?=$ano?></td>
                                        <td><?=$carga?></td>
										<td align="right"><?=formatear($valor_dia)?></td>											
                                        <td align="center">                                       
                                            <a href="formulario.php?p=1&id=<?=$id_vehiculo?>" class="btn btn-warning" style="padding:3px" title="Editar"> <i class="ri-pencil-fill"></i></a>                                   		
                                        </td>
                                    </tr>
									<?php
								}
								?>	                                    											
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
} 

function formulario_vehiculo($mysqli, $id){

	if ($id>0){
		$rs = getAllVehiculosById($mysqli, $id);
		$rows = $rs->fetch_assoc();
		$nombre = $rows['nombre'];
		$color = $rows['color'];
		$marca = $rows['marca'];
		$modelo = $rows['modelo'];
		$ano = $rows['ano'];
		$carga = $rows['carga'];
		$valor_dia = $rows['valor_dia'];
		$foto1 = $rows['foto1'];
		$foto2 = $rows['foto2'];
		$foto3 = $rows['foto3'];
		$foto4 = $rows['foto4'];
		$foto5 = $rows['foto5'];

		$capacidad_motor 	= $rows['capacidad_motor'];
		$capacidad_personas = $rows['capacidad_personas'];
		$tipo_transmision 	= $rows['tipo_transmision'];
		$tanque_combustible = $rows['tanque_combustible'];
		$direccion 			= $rows['direccion'];
		$velocidad_crucero 	= $rows['velocidad_crucero'];
		$sistema_frenado 	= $rows['sistema_frenado'];
		$alto_total			 = $rows['alto_total'];
		$ancho				 = $rows['ancho'];
		$largo 				= $rows['largo'];
		$frenos_traseros 	= $rows['frenos_traseros'];
		$frenos_delanteros 	= $rows['frenos_delanteros'];
		$aire_acondicionado = $rows['aire_acondicionado'];
		$climatizador 		= $rows['climatizador'];
		$conector 			= $rows['conector'];
		$sistema_audio		= $rows['sistema_audio'];
		$pantalla 			= $rows['pantalla'];
		$reproductor 		= $rows['reproductor'];
		$luz_delantera 		= $rows['luz_delantera'];
		$bocinas 			= $rows['bocinas'];
		$amortiguadores 	= $rows['amortiguadores'];
		$neumaticos 		= $rows['neumaticos'];
		$parachoque 		= $rows['parachoque'];
		$volante 			= $rows['volante'];
		$bolsa_aire 		= $rows['bolsa_aire'];
		$cocina 			= $rows['cocina'];
		$lavaplatos 		= $rows['lavaplatos'];
		$cooler 			= $rows['cooler'];
		$toldo_trasero 		= $rows['toldo_trasero'];
		$toldo_lateral 		= $rows['toldo_lateral'];
		$carpa_techo 		= $rows['carpa_techo'];
		$kit_cocina 		= $rows['kit_cocina'];
		$anexo_carpa 		= $rows['anexo_carpa'];
		$anexo_frontal 		= $rows['anexo_frontal'];
		$calefaccion 		= $rows['calefaccion'];
		$sistema_electrico 	= $rows['sistema_electrico'];
		$publicado 			= $rows['publicado'];
	}else{
		$nombre = "";
		$color = "";
		$marca = "";
		$modelo = "";
		$ano = "";
		$carga = "";
		$valor_dia = "";
		$foto1 = "";
		$foto2 = "";
		$foto3 = "";
		$foto4 = "";
		$foto5 = "";

		$capacidad_motor 	= "";
		$capacidad_personas = "";
		$tipo_transmision 	= "";
		$tanque_combustible = "";
		$direccion 			= "";
		$velocidad_crucero 	= "";
		$sistema_frenado 	= "";
		$alto_total			 = "";
		$ancho				 = "";
		$largo 				= "";
		$frenos_traseros 	= "";
		$frenos_delanteros 	= "";
		$aire_acondicionado = "";
		$climatizador 		= "";
		$conector 			= "";
		$sistema_audio		= "";
		$pantalla 			= "";
		$reproductor 		= "";
		$luz_delantera 		= "";
		$bocinas 			= "";
		$amortiguadores 	= "";
		$neumaticos 		= "";
		$parachoque 		= "";
		$volante 			= "";
		$bolsa_aire 		= "";
		$cocina 			= "";
		$lavaplatos 		= "";
		$cooler 			= "";
		$toldo_trasero 		= "";
		$toldo_lateral 		= "";
		$carpa_techo 		= "";
		$kit_cocina 		= "";
		$anexo_carpa 		= "";
		$anexo_frontal 		= "";
		$calefaccion 		= "";
		$sistema_electrico 	= "";
		$publicado 	= 0;


	}
   
	?>	
	<div class="page-title-box d-flex align-items-center justify-content-between">
		<h4 class="mb-0">Vehículo</h4>
		<div class="page-title-right">
			<ol class="breadcrumb m-0">
				<li class="breadcrumb-item"><a href="../index.php">Escritorio</a></li>
				<li class="breadcrumb-item active">Vehículo</li>
			</ol>
		</div>
	</div>
        <div class="content-body"><!-- Description -->
	
	
	      <div class="col-md-8 offset-2">
			<div class="card">
				
				<div class="card-content collapse show">
					<div class="card-body">
						<div class="card-text">
							<p>Información del vehículo</p>
						</div>
						<form class="m-t" role="form" action="act.php" method="post" enctype="multipart/form-data">
						   <input type="hidden" name="id" id="id" value="<?=$id?>">
						   <input type="hidden" name="tb_cc" id="tb_cc" value="1">						
						   <div class="form-actions" align="right"></div>						
							 <div class="form-body">														
								<div class="form-group  row"><label class="col-sm-3 col-form-label">Nombre</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="nombre" id="nombre" required="" value="<?=$nombre?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Marca</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="marca" id="marca" required="" value="<?=$marca?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Modelo</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="modelo" id="modelo" required="" value="<?=$modelo?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Año</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="ano" id="ano"  value="<?=$ano?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Color</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="color" id="color"  value="<?=$color?>" autocomplete="off"></div>
								</div>				
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Carga</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="carga" id="carga"  value="<?=$carga?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Valor diario</label>
									<div class="col-sm-3"><input type="text" class="form-control" name="valor_dia" id="valor_dia"  value="<?=$valor_dia?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Publicado</label>
									<div class="col-sm-3">
										<select name="publicado" id="publicado" class="form-control">
											<option value="0" <?php if ($publicado==0){ ?> selected <?php } ?>>No</option>
											<option value="1" <?php if ($publicado==1){ ?> selected <?php } ?>>Si</option>
										</select>
									</div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Foto 1</label>
									<div class="col-sm-9"><? if ($foto1!=NULL){ ?><img src="prod/<?=$foto1?>" width="200px"> <input type="checkbox" name="che1" id="che1" value="1"> Eliminar <? } ?><input type="file" name="foto1" id="foto1" class="form-control"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Foto 2</label>
									<div class="col-sm-9"><? if ($foto2!=NULL){ ?><img src="prod/<?=$foto2?>" width="200px"> <input type="checkbox" name="che2" id="che2" value="1"> Eliminar <? } ?><input type="file" name="foto2" id="foto2" class="form-control"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Foto 3</label>
									<div class="col-sm-9"><? if ($foto3!=NULL){ ?><img src="prod/<?=$foto3?>" width="200px"> <input type="checkbox" name="che3" id="che3" value="1"> Eliminar <? } ?><input type="file" name="foto3" id="foto3" class="form-control"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Foto 4</label>
									<div class="col-sm-9"><? if ($foto4!=NULL){ ?><img src="prod/<?=$foto4?>" width="200px"> <input type="checkbox" name="che4" id="che4" value="1"> Eliminar <? } ?><input type="file" name="foto4" id="foto4" class="form-control"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Foto 5</label>
									<div class="col-sm-9"><? if ($foto5!=NULL){ ?><img src="prod/<?=$foto5?>" width="200px"> <input type="checkbox" name="che5" id="che5" value="1"> Eliminar <? } ?><input type="file" name="foto5" id="foto5" class="form-control"></div>
								</div>

								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Capacidad de motor</label>
									<label class="col-sm-3 col-form-label">Capacidad personas</label>
									<label class="col-sm-3 col-form-label">Tipo de transmisión</label>
									<label class="col-sm-3 col-form-label">Tanque combustible</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="capacidad_motor" id="capacidad_motor"  value="<?=$capacidad_motor?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="capacidad_personas" id="capacidad_personas"  value="<?=$capacidad_personas?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="tipo_transmision" id="tipo_transmision"  value="<?=$tipo_transmision?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="tanque_combustible" id="tanque_combustible"  value="<?=$tanque_combustible?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Dirección</label>
									<label class="col-sm-3 col-form-label">Velocidad crucero</label>
									<label class="col-sm-3 col-form-label">Sistema de frenado</label>
									<label class="col-sm-3 col-form-label">Alto total</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="direccion" id="direccion"  value="<?=$direccion?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="velocidad_crucero" id="velocidad_crucero"  value="<?=$velocidad_crucero?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="sistema_frenado" id="sistema_frenado"  value="<?=$sistema_frenado?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="alto_total" id="alto_total"  value="<?=$alto_total?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Ancho</label>
									<label class="col-sm-3 col-form-label">Largo</label>
									<label class="col-sm-3 col-form-label">Frenos traseros</label>
									<label class="col-sm-3 col-form-label">Frenos delanteros</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="ancho" id="ancho"  value="<?=$ancho?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="largo" id="largo"  value="<?=$largo?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="frenos_traseros" id="frenos_traseros"  value="<?=$frenos_traseros?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="frenos_delanteros" id="frenos_delanteros"  value="<?=$frenos_delanteros?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Aire acondicionado</label>
									<label class="col-sm-3 col-form-label">Climatizador</label>
									<label class="col-sm-3 col-form-label">Conector</label>
									<label class="col-sm-3 col-form-label">Sistema de audio</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="aire_acondicionado" id="aire_acondicionado"  value="<?=$aire_acondicionado?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="climatizador" id="climatizador"  value="<?=$climatizador?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="conector" id="conector"  value="<?=$conector?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="sistema_audio" id="sistema_audio"  value="<?=$sistema_audio?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Pantalla</label>
									<label class="col-sm-3 col-form-label">Reproductor</label>
									<label class="col-sm-3 col-form-label">Luz delantera</label>
									<label class="col-sm-3 col-form-label">Bocinas</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="pantalla" id="pantalla"  value="<?=$pantalla?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="reproductor" id="reproductor"  value="<?=$reproductor?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="luz_delantera" id="luz_delantera"  value="<?=$luz_delantera?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="bocinas" id="bocinas"  value="<?=$bocinas?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Amortiguadores</label>
									<label class="col-sm-3 col-form-label">Neumáticos</label>
									<label class="col-sm-3 col-form-label">Parachoque</label>
									<label class="col-sm-3 col-form-label">Volante</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="amortiguadores" id="amortiguadores"  value="<?=$amortiguadores?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="neumaticos" id="neumaticos"  value="<?=$neumaticos?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="parachoque" id="parachoque"  value="<?=$parachoque?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="volante" id="volante"  value="<?=$volante?>" autocomplete="off"></div>
								</div>								
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Bolsa de aire</label>
									<label class="col-sm-3 col-form-label">Cocina</label>
									<label class="col-sm-3 col-form-label">Lavaplatos</label>
									<label class="col-sm-3 col-form-label">Cooler</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="bolsa_aire" id="bolsa_aire"  value="<?=$bolsa_aire?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="cocina" id="cocina"  value="<?=$cocina?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="lavaplatos" id="lavaplatos"  value="<?=$lavaplatos?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="cooler" id="cooler"  value="<?=$cooler?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Toldo trasero</label>
									<label class="col-sm-3 col-form-label">Toldo lateral</label>
									<label class="col-sm-3 col-form-label">Carpa techo</label>
									<label class="col-sm-3 col-form-label">Kit cocina</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="toldo_trasero" id="toldo_trasero"  value="<?=$toldo_trasero?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="toldo_lateral" id="toldo_lateral"  value="<?=$toldo_lateral?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="carpa_techo" id="carpa_techo"  value="<?=$carpa_techo?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="kit_cocina" id="kit_cocina"  value="<?=$kit_cocina?>" autocomplete="off"></div>
								</div>								
								<div class="form-group  row" style="margin-top: 10px;">
									<label class="col-sm-3 col-form-label">Anexo carpa</label>
									<label class="col-sm-3 col-form-label">Anexo frontal</label>
									<label class="col-sm-3 col-form-label">Calefacción</label>
									<label class="col-sm-3 col-form-label">Sistema eléctrico</label>
								</div>
								<div class="form-group row">	
									<div class="col-sm-3"><input type="text" class="form-control" name="anexo_carpa" id="anexo_carpa"  value="<?=$anexo_carpa?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="anexo_frontal" id="anexo_frontal"  value="<?=$anexo_frontal?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="calefaccion" id="calefaccion"  value="<?=$calefaccion?>" autocomplete="off"></div>
									<div class="col-sm-3"><input type="text" class="form-control" name="sistema_electrico" id="sistema_electrico"  value="<?=$sistema_electrico?>" autocomplete="off"></div>
								</div>
								
												
							</div>
							<br><br>
							<div class="form-actions" align="right">
                                <a href="index.php?p=1" class="btn btn-warning"><i class="ft-x"></i> Volver</a> 						
								<button type="submit" class="btn btn-success">
									<i class="fa fa-check"></i> Grabar
								</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>	
		</div>
     	
	<?php

}

function lista_sucursales($mysqli){
    ?>
  
			<div class="content-header row">
			  <div class="content-header-left col-md-6 col-12 mb-1">
				<h3 class="content-header-title">Sucursales de la empresa</h3>
			  </div>          
			</div>
			<div class="content-body"><!-- Description -->

			 <div class="row">
					<div class="col-12">
						<div class="card">						
							<div class="card-content">
								<div class="card-body card-dashboard">
								   <table width="100%" border="0">
									<tr>
										<td><p class="card-text">Información de sucursales</p></td>
										<td align="right">
                                           <a href="formulario.php?p=2" class="btn btn-info">+ Nueva</a>								
										</td>
									</tr>
								   </table>

								</div>
								<div class="table-responsive">
									<table class="table table-bordered mb-0">
										<thead>
											<tr>											
											    
											    <th>Nombre</th>												
												<th>Dirección</th>												
												<th>Teléfono</th>
												<th>Región</th>
                                                <th>Comuna</th>
																																
												<th width="5%">Acción</th>
											</tr>
										</thead>
										<tbody>
										<?php
										$i=1;
										$sql = $mysqli->query("select * from tb_sucursal");
										while ($rows = $sql->fetch_assoc()){
											$id_sucursal    = $rows['id_sucursal'];
											$nombre         = $rows['nombre'];
											$direccion      = $rows['direccion'];
											$id_comuna      = $rows['id_comuna'];
											$id_region      = $rows['id_region'];
											$telefono       = $rows['telefono'];
											
											$sql2 = $mysqli->query("select * from tb_regiones where id_region='$id_region'");
											$rows2 = $sql2->fetch_assoc();
											$nombre_region = $rows2['nombre'];

											$sql2 = $mysqli->query("select * from tb_comunas where id_comuna='$id_comuna'");
											$rows2 = $sql2->fetch_assoc();
											$nombre_comuna = $rows2['nombre'];
											?>
											<tr>												
											    
											    <td><?=$nombre?></td>
												<td align="center"><?=$direccion?></td>
												<td><?=$telefono?></td>
												<td><?=$nombre_region?></td>
                                                <td><?=$nombre_comuna?></td>											
												<td align="center">												
                                                    <a href="formulario.php?p=2&id=<?=$id_sucursal?>" class="btn btn-warning"  style="padding: 6px;">Editar</a>
												</td>
											</tr>
									        <?php 
										  $i++;	

										} ?>												
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>

			</div>
		  
        <?php  
}


?>          
