<?php
include('clases/clase.conexion.php');
include('../funciones/variables.php');
include('../funciones/funciones.php');
$var = VarServer("MYSQLI");
$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
$sql = "select date_format(C.fecha_emision,'%d/%m/%Y') AS FECHA, 
		T.nombre as TIPO, C.nro_documento as NUMERO,
		CONCAT(C.id_cliente,' - ', UPPER(P.nombre)) as CLIENTE, upper(P.direccion) AS DIRECCION,
		cv.nombre AS CONDICION,
		P.ruc
		from _sv_venta C
		inner join _sv_Cliente P ON C.id_Cliente = P.id_Cliente
		inner join _sv_tipo_doc_pago T ON C.id_tipo_doc = T.id_tipo_doc
		inner join _sv_tipo_condicion CV ON C.id_condicion = CV.id_condicion
		where C._estado='A'
		AND C.id_venta=$_GET[ndoc]";
$obj->AbrirConexion();
$rs = $obj->Query($sql);
$obj->CerrarConexion();
$row = $obj->FetchArray($rs);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="STYLESHEET" href="../css/print_factura.css" type="text/css" />
<link rel="STYLESHEET" type="text/css" href="estilo.css">
 <link rel="STYLESHEET" type="text/css" href="estilo_imprimir.css" media="print">
</head>

<body>

<div id="body">

<div id="section_header">
</div>

<div id="content">
  
<div class="page" style="font-size: 10pt">

<table style="width: 100%;" class="header">
<tr>
<td><h1 style="text-align: left"><?php echo $varSysEmpresa; ?></h1></td>
<td><h1 style="text-align: right; font-size: 10pt;"><?php echo $row["NUMERO"]; ?></h1></td>
</tr>
</table>

<table style="width: 100%; font-size: 8pt;">
<tr>
<td><?php echo $$varSysRuc; ?></td>
<td style="text-align: right"><?php echo $row["TIPO"]; ?></td>
</tr>
</table>

<table style="width: 100%; font-size: 8pt;">
<tr>
<td><strong>Cliente</strong></td>
<td>:</td>
<td  style="width:230px; font-size: 8pt;"><?php echo $row["CLIENTE"]; ?></td>
<td>&nbsp;</td>
<td><strong>F. Emisión</strong></td>
<td>: </td>
<td style="text-align: right"><?php echo $row["FECHA"]; ?></td>
</tr>
<tr>
<td><strong>Dirección</strong></td>
<td>:</td>
<td><?php echo $row["DIRECCION"]; ?></td>
<td>&nbsp;</td>
<td><strong>Condicion</strong></td>
<td>: </td>
<td style="text-align: right"><?php echo $row["CONDICION"]; ?></td>
</tr>
</table>
<table class="change_order_items">
<tbody>
<tr>
<th width="10" style="border: 1px solid black; font-size: 8pt;">Id</th>
<th width="100" style="border: 1px solid black; font-size: 8pt;">Descripcion</th>
<th width="20" style="border: 1px solid black; font-size: 8pt;">Precio</th>
<th width="20" style="border: 1px solid black; font-size: 8pt;">Cantidad</th>
<th width="20" style="border: 1px solid black; font-size: 8pt;">Monto</th>
</tr>
<?php
$sql = "select D.id_producto AS CPRO, A.descripcion AS PRODUCTO, D.PRECIO, D.CANTIDAD, D.TOTAL
		from _sv_venta_detalle D
		inner join _sv_producto A ON D.id_producto = A.id_producto
		where D.id_venta=$_GET[ndoc]";
$obj->AbrirConexion();
$rs = $obj->Query($sql);
$obj->CerrarConexion();
$j=0;
$bgcolor1 = 'class="even_row" ';
$bgcolor2 = 'class="odd_row" ';
$varTotal = 0;
while($fila = $obj->FetchArray($rs))	{
	$varTotal = $varTotal + $fila["TOTAL"]; 
	$j++;
	$bg = ($j%2==0)? $bgcolor1: $bgcolor2;
?>
		<tr <?php echo $bg; ?> >
        <td style="text-align:center;"><?php echo $fila["CPRO"];?></td>
		<td><?php echo $fila["PRODUCTO"];?></td>
		<td style="text-align: right">
        <?php
		if(!is_null($fila["PRECIO"]) && $fila["PRECIO"]<>0)
			echo number_format($fila["PRECIO"],"2",".",",");
		?>
		</td>
		<td style="text-align: center">
		<?php
        if(!is_null($fila["CANTIDAD"]) && $fila["CANTIDAD"]<>0)
			echo number_format($fila["CANTIDAD"],"0",".",",");
		?>
		</td>
		<td style="text-align: right">
        <?php
		if(!is_null($fila["TOTAL"]) && $fila["TOTAL"]<>0)
			echo number_format($fila["TOTAL"],"2",".",",");
		?>
		</td>
		</tr>
<?php
	}
	?>
</tbody>
<tr>
<td height="26" colspan="4" style="text-align: right;"><strong> TOTAL : </strong></td>
<td class="change_order_total_col"><strong><?php echo number_format($varTotal,"2",".",","); ?></strong>&nbsp;</td></tr>
</table>

</div>

</div>
</div>
</body>
</html>