<?php  
	session_start();
	include "conexion.php";
	include 'mysql_Agregar_auditoria.php';

	if (!isset($_SESSION['id_usuario']))
	{
		header('location: index.php');
		return;
	}

	$id_transaccion = $_POST['id_transaccion'];

	$sql = "select ";
    $sql .= "id_transaccion, ";
    $sql .= "id_tipo, ";
    $sql .= "date_format(fecha,'%Y-%m-%d %H:%i:%s') as fecha, ";
    $sql .= "id_cliente, ";
    $sql .= "id_vehiculo, ";
    $sql .= "ifnull(monto,0) as monto, ";
    $sql .= "ifnull(saldo,0) as saldo, ";
    $sql .= "id_turno, ";
    $sql .= "descripcion, ";
    $sql .= "placa, ";
    $sql .= "id_tag, ";
    $sql .= "ifnull(odometro,0) as odometro, ";
    $sql .= "ifnull(odometro_diferencia,0) as odometro_diferencia, ";
    $sql .= "clase, ";
    $sql .= "factura ";
    $sql .= "from ";
    $sql .= "transacciones ";
    $sql .= "where ";
    $sql .= "id_transaccion=".$id_transaccion;

	$resultado = $conexion->query($sql); 

	if(!$resultado) 
		die("Error: no se pudo realizar la consulta");

	while($fila = $resultado->fetch_assoc())
	{
		$id_tipo = $fila['id_tipo'];
		$fecha = $fila['fecha'];
		$id_cliente = $fila['id_cliente'];
		$id_turno = $fila['id_turno'];
		$factura = $fila['factura'];
		$posicion ="";
		$id_vehiculo = $fila['id_vehiculo'];
		$descripcion = $fila['descripcion'];
		$monto = number_format($fila['monto'], 2, '.', ',');
		$saldo = number_format($fila['saldo'], 2, '.', ',');
		$clase = $fila['clase'];
		$placa = $fila['placa'];
		$id_tag=$fila['id_tag'];		
		$odometro =number_format( $fila['odometro'], 0, '.', ',');
		$odometro_diferencia = number_format($fila['odometro_diferencia'], 0, '.', ',');
	}

	$resultado->free(); 

?>

<div class="row form-group">

	<h1>Detalle Transacción</h1>
	
</div>
<div class="row form-group">	
	<div class="col-md-1 offset-md-11 ">
		<button class="btn btn-danger" onclick="regresar_detalle();">Regresar</button>
	</div>
</div>

<div class="form-group">
	<div class="row">
		<div class="col-md-3">
			<label>Id Transaccion</label>
			<input type="" name="" class="form-control" value="<?php echo $id_transaccion; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>	Id Tipo</label>
			<input  type='' name=""  class="form-control" value="<?php echo $id_tipo; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>Fecha</label>
			<input  type='' name=""  class="form-control" value="<?php echo $fecha; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>Id Cliente</label>
			<input  type='' name=""  class="form-control" value="<?php echo $id_cliente; ?>" readonly>
		</div>
	</div>
	<div class="row">
		<div class="col-md-3">
			<label>	Id Turno</label>
			<input type="" name="" class="form-control" value="<?php echo $id_turno; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>	Factura</label>
			<input  type='' name=""  class="form-control" value="<?php echo $factura; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>Id Vehiculo</label>
			<input  type='' name="" class="form-control" value="<?php echo $id_vehiculo; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>Posición</label>
			<input  type='' name=""  class="form-control" value="<?php echo $posicion; ?>" readonly>
		</div>
	</div>

	<div class="row">
		<div class="col-md-3">
			<label>	Descripcion</label>
			<input type="" name="" class="form-control" value="<?php echo $descripcion; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>	Monto</label>
			<input  type='' name="" style="text-align:right;" class="form-control" value="<?php echo $monto; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>Saldo</label>
			<input  type='' name="" style="text-align:right;" class="form-control" value="<?php echo $saldo; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>Clase</label>
			<input  type='' name="" class="form-control" value="<?php echo $clase; ?>" readonly>
		</div>
	</div>

	<div class="row">
		<div class="col-md-3">
			<label>	Placa</label>
			<input type="" name="" class="form-control" value="<?php echo $placa; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>	Id Tag</label>
			<input  type='' name="" style="text-align:right;" class="form-control" value="<?php echo $id_tag; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>Odómetro</label>
			<input  type='' name="" style="text-align:right;" class="form-control" value="<?php echo $odometro; ?>" readonly>
		</div>
		<div class="col-md-3">
			<label>	Odómetro Diferencia</label>
			<input  type='' name="" style="text-align:right;"  class="form-control" value="<?php echo $odometro_diferencia; ?>" readonly>
		</div>
	</div>

</br></br>
	<?php 
		$sql = "select ";
        $sql .= "date_format(v.fecha_venta,'%Y-%m-%d %H:%i:%s') as fecha_venta, ";
        $sql .= "v.id_venta, ";
        $sql .= "v.id_producto,  ";
        $sql .= "p.nombre, ";
        $sql .= "v.id_bomba, ";
        $sql .= "ifnull(v.volumen,0) as volumen,  ";
        $sql .= "ifnull(v.monto,0) as monto ";
        $sql .= "from gaslight.ventas v, gaslight.productos p ";
        $sql .= "where  ";
        $sql .= "v.id_producto = p.id_producto ";
        $sql .= "and id_venta in  ";
        $sql .= "(select id_venta  ";
        $sql .= "from gaslight.transacciones_detalle  ";
        $sql .= "where id_transaccion =" . $id_transaccion . ") ";

        $resultado = $conexion->query($sql); 

		if(!$resultado) 
			die("Error: no se pudo realizar la consulta");

		echo "<table id='tabla_detalle' class='table table-sm table-striped' >";
		echo "<thead>";
			echo "<th >Fecha Registro</td>";
			echo "<th >Venta</td>";
			echo "<th >Producto</td>";
			echo "<th >Nombre</td>";
			echo "<th >Bomba</td>";
			echo "<th width='180' align='right'>Volumen</td>";
			echo "<th width='180' align='right'>Monto</td>";
		echo "</thead>";		
		echo "<tbody>";
		
		while($fila2 = $resultado->fetch_assoc())
		{
			
			echo "<tr  style='height:30px;'>";
			echo "<td align='center'>".$fila2['fecha_venta']."</td>";
			echo "<td align='center'>".$fila2['id_venta']."</td>";
			echo "<td align='center'>".$fila2['id_producto']."</td>";
			echo "<td align='center'>".$fila2['nombre']."</td>";
			echo "<td align='center'>".$fila2['id_bomba']."</td>";
			echo "<td align='right'>".number_format($fila2['volumen'],2,'.',',')."</td>";
			echo "<td align='right'>".number_format($fila2['monto'],2,'.',',')."</td>";
			echo "</tr>";		
		}
		echo "</tbody>";
		echo "</table>";


		$informacion = 'Ingreso a Detalle Transacción '.$id_transaccion;
		$datos = "";
		insertAuditoria($informacion,$datos,$_SESSION['id_usuario'],$_SESSION['direccion_ip'],$_SESSION['direccion_mac']);	
		mysqli_close($conexion);

    ?>
	

	
</div>