<?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,
		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_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);
$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>Impresion de Factura</title></head>
<link href="../css/factura.css" rel="stylesheet" type="text/css" > 
<link rel="stylesheet" href="../css/factura2.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_renacer.jpg" width="595" height="141" /></div></td>
        <td width="182" height="25" align="center" valign="middle"><div id="noPrint"><b>R.U.C. 20480176732</b></div></td>
        </tr>
      <tr>
        <td height="25" align="center" valign="middle"><div id="noPrint"><b><?php echo $row["TIPO"]; ?></b></div></td>
        </tr>
        <tr>
          <td height="25" align="center" valign="middle"><?php echo $row["NUMERO"]; ?></td>
        </tr>
        <tr>
          <td height="50" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
          <td  align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        </tr>
    </table>
        </td>
      </tr>
      <tr>
        <td>
    <table width="100%" border="0" class="cabecera">
      <tr>
        <td width="10%" height="25" align="left"><div id="noPrint"><b>Se&ntilde;or(es)</b></div></td>
        <td width="1%"><div id="noPrint"><b>:</b></div></td>
        <td width="66%" align="left" class="size1"><?php echo $row["CLIENTE"]; ?></td>
        <td width="12%" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td width="1%" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td width="10%" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
      </tr>
      <tr>
        <td height="25"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td align="left"><div id="noPrint"><b>Fecha</b></div></td>
        <td><div id="noPrint"><b>:</b></div></td>
        <td><?php 
        $fecha = explode("/",$row["FECHA"]);
        echo $fecha[0]."&nbsp;&nbsp;".$fecha[1]."&nbsp;&nbsp;".$fecha[2]; 
        ?></td>
      </tr>
        <tr>
        <td height="30" align="left"><div id="noPrint"><b>Direccion</b></div></td>
        <td><div id="noPrint"><b>:</b></div></td>
        <td align="left"><?php echo $row["DIRECCION"]; ?></td>
        <td><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td><!--DWLayoutEmptyCell-->&nbsp;</td>
      </tr>
        <tr>
        <td height="30" align="left"><div id="noPrint"><b>Nro. RUC</b></div></td>
        <td><div id="noPrint"><b>:</b></div></td>
        <td align="left"><?php echo $row["RUC"]; ?></td>
        <td align="left"><div id="noPrint"><b>Guia de Remision N&ordm;</b></div></td>
        <td><div id="noPrint"><b>:</b></div></td>
        <td><!--DWLayoutEmptyCell-->&nbsp;</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="5%" align="center" valign="middle" class="contorno">&nbsp;</td>
        <td width="8%" height="25" align="center" valign="middle" class="contorno"><div id="noPrint"><strong>Cantidad</strong></div></td>
        <td width="8%" 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="12%" align="center" valign="middle" class="contorno"><div id="noPrint"><b>P. Unit.</b></div></td>
        <td width="12%" align="center" valign="middle" class="contorno"><div id="noPrint"><strong>Valor Venta</strong></div></td>
      </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"]; 
        ?>
      <tr>
        <td align="center" valign="middle" class="contorno2">&nbsp;</td>
        <td align="center" valign="middle" class="contorno2"><?php
        if(!is_null($fila["CANTIDAD"]) && $fila["CANTIDAD"]<>0)
            echo number_format($fila["CANTIDAD"],"0",".",",");
        ?></td>
        <td align="center" valign="middle" class="contorno2"><?php
        if(!is_null($fila["UNIDAD"]) && $fila["UNIDAD"]<>"")
            echo $fila["UNIDAD"];
        ?></td>
        <td align="left" valign="middle" class="contorno2"><?php echo $fila["PRODUCTO"];?></td>
        <td align="right" valign="middle" class="contorno2"><?php
            if(!is_null($fila["PRECIO"]) && $fila["PRECIO"]<>0)
                echo number_format($fila["PRECIO"],"2",".",",");
            ?></td>
        <td align="right" valign="middle" class="contorno2"><?php
            if(!is_null($fila["TOTAL"]) && $fila["TOTAL"]<>0)
                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="10%" height="25" align="center" valign="middle" class="contorno"><div id="noPrint"><strong>Son</strong></div></td>
        <td width="70%" align="left" valign="middle" class="contorno2"><?php echo strtoupper($obj_numlet->convertir($row["TOTAL"]));?></td>
        <td width="10%" align="right" valign="middle" class="contorno"><div id="noPrint"><b>Sub Total :</b></div></td>
        <td width="10%" align="right" valign="middle" class="contorno2"> 
		<?php
	if(!is_null($row["SUBTOTAL"]) && $row["SUBTOTAL"]<>0)
		echo number_format($row["SUBTOTAL"],"2",".",",");
	?></td>
      </tr>
      <tr>
        <td height="25" align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td align="right" valign="middle" class="contorno"><div id="noPrint"><b>I.G.V. :</b></div></td>
        <td align="right" valign="middle" class="contorno2">
        <?php
		if(!is_null($row["IGV"]) && $row["IGV"]<>0)
			echo number_format($row["IGV"],"2",".",",");
		?>        </td>
      </tr>
      <tr>
        <td height="25" align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td align="right" valign="middle" class="contorno"><div id="noPrint"><b>Total :</b></div></td>
        <td align="right" valign="middle" 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>
