<?php
include('../clases/clase.conexion.php');
include('../clases/clase.numeroletras.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,
		C.nro_guia as GUIA, C.id_vendedor as CVEN,
		CONCAT(C.id_cliente,' - ', UPPER(P.nombre)) as CLIENTE, upper(P.direccion) AS DIRECCION,
		CV.nombre AS CONDICION,	P.RUC, C.SUBTOTAL, C.IGV, C.TOTAL
		from _sv_venta C
		inner join _sv_cliente P ON C.id_Cliente = P.id_Cliente
		inner join _sv_tipo_doc_venta 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);
$obj_numlet = new numerosALetras;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<title>IMPRIMIR FACTURA</title></head>
<link href="../css/factura.css" rel="stylesheet" type="text/css" > 
<link rel="stylesheet" href="../css/factura_epsonlx300.css" type="text/css" media="print" />
<body>
<div id="container">
    <table width="100%" border="0" class="mainContent">
      <tr>
        <td>
        <table width="100%" border="0" class="factura">
          <!--DWLayoutTable-->
      <tr>
        <td width="616" rowspan="3" align="left" valign="top"><div id="noPrint"><img src="../images/logo.jpg" width="350" height="90" /></div></td>
        <td width="182" height="30" align="center" valign="middle"><div id="noPrint"><b>R.U.C. <?php echo Config("SYSRUC")?></b></div></td>
        </tr>
      <tr>
        <td height="30" align="center" valign="middle"><div id="noPrint"><b><?php echo $row["TIPO"]; ?></b></div></td>
        </tr>
        <tr>
          <td height="30" align="center" valign="top"><?php echo $row["NUMERO"]; ?></td>
        </tr>
    </table>
        </td>
      </tr>
      <tr>
        <td>
    <table width="100%" border="0" class="cabecera">
      <tr>
        <td width="17%" height="20" align="left"><div id="noPrint"><b>Se&ntilde;or(es)</b></div></td>
        <td width="1%"><div id="noPrint"><b>:</b></div></td>
        <td colspan="3" align="left"><?php echo $row["CLIENTE"]; ?></td>
        <td width="9%" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td width="1%" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td width="8%" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td colspan="3" valign="top"><div id="noPrint" align="center"><b>Fecha Emisi&oacute;n</b></div></td>
        </tr>
        <tr>
        <td height="20" align="left"><div id="noPrint"><b>Direccion</b></div></td>
        <td><div id="noPrint"><b>:</b></div></td>
        <td colspan="6" align="left" nowrap="nowrap"><?php echo substr($row["DIRECCION"],0,80); ?></td>
        <td width="80"><div id="noPrint" align="center"><b>DIA</b></div></td>
        <td width="80"><div id="noPrint" align="center"><b>MES</b></div></td>
        <td width="80"><div id="noPrint" align="center"><b>A&Ntilde;O</b></div></td>
        </tr>
      <tr>
        <td height="20" align="left"><div id="noPrint"><b>Nro. RUC</b></div></td>
        <td><div id="noPrint"><b>:</b></div></td>
        <td width="30%" align="left"><?php echo $row["RUC"]; ?></td>
        <td width="10%" align="left"><div id="noPrint"><b>Vend. :</b></div></td>
        <td width="10%" align="center"><?php echo $row["CVEN"]; ?></td>
        <td align="left"><div id="noPrint"><b>Guia R.</b></div></td>
        <td><div id="noPrint"><b>:</b></div></td>
        <td><?php echo $row["GUIA"]; ?></td>
        <td align="center" valign="top"><?php 
        $fecha = explode("/",$row["FECHA"]);
        echo $fecha[0]; 
        ?>&nbsp;&nbsp;&nbsp;</td>
        <td align="center" valign="top">&nbsp;&nbsp;&nbsp;<?php echo $fecha[1]; ?>&nbsp;&nbsp;&nbsp;</td>
        <td align="center" valign="top">&nbsp;&nbsp;&nbsp;<?php echo $fecha[2]; ?></td>
      </tr>
    </table>
        </td>
      </tr>
      <tr>
        <td>
     <table width="100%" border="0" class="detalle" >
      <tr>
        <td valign="top">
      <table width="100%" border="0" class="detalle2" cellpadding="0" cellspacing="0">
      <tr>
        <td width="8%" align="center" valign="middle" class="contorno"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td width="5%" height="25" align="center" valign="middle" class="contorno"><div id="noPrint"><strong>Cantidad</strong></div></td>
        <td width="5%" align="center" valign="middle" class="contorno"><div id="noPrint"><b>Unidad</b></div></td>
        <td width="60%" align="center" valign="middle" class="contorno" ><div id="noPrint"><b>Descripcion</b></div></td>
        <td width="8%" align="center" valign="middle" class="contorno"><div id="noPrint"><b>P. Unit.</b></div></td>
        <td width="8%" align="center" valign="middle" class="contorno"><div id="noPrint"><b>Valor Venta</b></div></td>
      </tr>
      <?php
		$sql = "call spQuery_Registro_Ventas_Contenido($_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"]; 
        ?>
      <tr>
        <td align="center" valign="middle" class="contorno2">&nbsp;</td>
        <td align="center" valign="middle" class="contorno2"><?php echo number_format($fila["CANTIDAD"],"2",".",","); ?></td>
        <td align="center" valign="middle" class="contorno2"><?php
        if(!is_null($fila["UM"]) && $fila["UM"]<>"")
            echo $fila["UM"];
        ?></td>
        <td align="left" valign="middle" class="contorno2"><?php echo $fila["CPRO"]." - ".substr($fila["PRODUCTO"],0,45);?></td>
        <td align="right" valign="middle" class="contorno2"><?php echo number_format($fila["PRECIO"],"5",".",","); ?></td>
        <td align="right" valign="middle" class="contorno2"><?php echo number_format($fila["TOTAL"],"2",".",","); ?></td>
      </tr>
      <?php } ?>
    </table>
        </td>
      </tr>
    </table>
        </td>
      </tr>
      <tr>
        <td>
        <table width="100%" border="0" class="resumen" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
      <tr>
        <td width="8%" height="20" align="center" valign="middle" class="contorno"><div id="noPrint"><strong>Son</strong></div></td>
        <td width="53%" align="left" valign="middle" class="contorno2"><?php echo strtoupper($obj_numlet->convertir($row["TOTAL"]));?></td>
        <td width="17%" align="center" valign="middle" class="contorno"><div id="noPrint"><b>Sub Total :</b></div></td>
        <td width="17%" align="center" valign="middle" class="contorno"><div id="noPrint"><b>I.G.V. :</b></div></td>
        <td width="17%" align="center" valign="middle" class="contorno"><div id="noPrint"><b>Total :</b></div>
		</td>
      </tr>
      <tr>
        <td height="30" align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td align="center" valign="bottom" class="contorno2">
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<?php
		if(!is_null($row["SUBTOTAL"]) && $row["SUBTOTAL"]<>0)
			echo number_format($row["SUBTOTAL"],"2",".",",");
		?></td>
        <td align="center" valign="bottom" class="contorno2">
        <?php
		if(!is_null($row["IGV"]) && $row["IGV"]<>0)
			echo number_format($row["IGV"],"2",".",",");
		?></td>
        <td align="center" valign="bottom" class="contorno2">
        <?php
		if(!is_null($row["TOTAL"]) && $row["TOTAL"]<>0)
			echo number_format($row["TOTAL"],"2",".",",");
		?>        </td>
      </tr>
    </table>
        </td>
      </tr>
    </table>
</div>
</body>
</html>
