<?php

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Proforma.xls");

 include ("../conectar.php");	
 
   
$query="SELECT * FROM web_0000";
$rs_query=mysql_query($query);
$NombreComercial=mysql_result($rs_query,0,"NOMCOM");
$Razon=mysql_result($rs_query,0,"RAZSOC");
$Cedula=mysql_result($rs_query,0,"CEDJUR");
$Direccion=mysql_result($rs_query,0,"DIREMP");
$Telefono=mysql_result($rs_query,0,"NUMTEL");


	 $parametros = "Select * from  web_0000";
$datos = mysql_query($parametros);
$codproforma=$_GET["codproforma"];

   $query_factura_contado="SELECT * FROM proformas WHERE codproforma='$codproforma'";

   $rs_query_factura_contado=mysql_query($query_factura_contado);

   $cdgcli= mysql_result($rs_query_factura_contado,0,"cdgcli");
   $cdgtipven= mysql_result($rs_query_factura_contado,0,"cdgtipven");
    $cdgven= mysql_result($rs_query_factura_contado,0,"cdgven");
	 $obsped= mysql_result($rs_query_factura_contado,0,"obsped");
	$horped= mysql_result($rs_query_factura_contado,0,"horfac");


   $query_vendedor="SELECT * FROM usuarios WHERE codusu=$cdgven";
   $rs_query_vendedor=mysql_query($query_vendedor);
   $dscven= mysql_result($rs_query_vendedor,0,"usu");

 if ($cdgtipven ==2 ) {

     $faccre = "";
	 $faccon = "CREDITO";
	 $facval= "";
 
	 
	} else {
	
	 $faccre = "";
	 $faccon = "CONTADO";
	 $facval= "";
	

	}
	
  	 if ($cdgcli == 9999) {

 $consulta = "Select * from proformas, web_0301 where proformas.codproforma='$codproforma' and proformas.cdgcli= $cdgcli";
 $resultado = mysql_query($consulta);
 $lafila=mysql_fetch_array($resultado);
  $subtot =mysql_result($resultado,0,"subtot");
 $impven =mysql_result($resultado,0,"impven");
 $destot =mysql_result($resultado,0,"destot");
 $totalproforma =mysql_result($resultado,0,"totalproforma");
 
 $fecha =mysql_result($resultado,0,"fecha");
 $dsccli= mysql_result($rs_query_factura_contado,0,"dsccli");
 $cedcli="";
    $chksug =mysql_result($resultado,0,"chksug");
 $numproforma =mysql_result($resultado,0,"numproforma");

		} else {

 $consulta = "Select * from proformas, web_0301 where proformas.codproforma='$codproforma' and proformas.cdgcli= web_0301.cdgcli";
 $resultado = mysql_query($consulta);
 $lafila=mysql_fetch_array($resultado);
 $dsccli=mysql_result($resultado,0,"dsccli");
 $cedcli=mysql_result($resultado,0,"cedcli");
 $dircli=mysql_result($resultado,0,"dircli");
 $numtel=mysql_result($resultado,0,"numtel");
 $fecha =mysql_result($resultado,0,"fecha");
 $subtot =mysql_result($resultado,0,"subtot");
 $impven =mysql_result($resultado,0,"impven");
 $destot =mysql_result($resultado,0,"destot");
 $totalproforma =mysql_result($resultado,0,"totalproforma");
 $numproforma =mysql_result($resultado,0,"numproforma");
 $fechavencimiento =mysql_result($resultado,0,"fechavencimiento");
 $chksug =mysql_result($resultado,0,"chksug");
      }  

  $fecha= implode("-", array_reverse(explode("-", $fecha))); 
  $fechavencimiento= implode("-", array_reverse(explode("-", $fechavencimiento))); 

					
?>
<!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=utf-8" />

<title>Reporte Analitico de Compras </title>
<style type="text/css">
<!--
.Estilo1 {color: #CCCCCC}
.Estilo6 {
	color: #000000;
	font-weight: bold;
}
.Estilo17 {color: #000000; font-weight: bold; font-size: 14px; }
.Estilo24 {font-size: 14px}
.Estilo29 {font-size: 14px; font-weight: bold; }
-->
</style>
</head>
<body>
<table width="92%" border="0" cellspacing="0" cellpadding="0">
    
    
    <tr>
      <td colspan="2" rowspan="5"  ><img src="http://localhost/img/Logo_reportes.png"  /></td>
      <td colspan="2" ><font size=5 ><?php echo $NombreComercial?></font></td>
      <td colspan="2" ><div align="center"><strong><font size="4" >PROFORMA N°</font> </strong></div></td>
      <td ><div align="center"><strong><font size="4" ><?php echo $numproforma; ?></font></strong></div></td>
    </tr>
    <tr>
      <td ><font size="3" ><?php echo $Razon?></font></td>
      <td >&nbsp;</td>
      <td colspan="2" >&nbsp;</td>
      <td ><div align="center"></div></td>
    </tr>
    <tr>
      <td ><font size="2" ><?php echo "Cédula " .$Cedula; ?></font></td>
      <td >&nbsp;</td>
      <td >&nbsp;</td>
      <td >&nbsp;</td>
      <td >&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" ><font size="2" ><?php echo $Direccion; ?></font></td>
      <td colspan="2"  ><div align="center"></div></td>
      <td  align="center">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" ><font size="2" ><?php echo $Telefono; ?></font></td>
      <td colspan="2"  ><div align="center"></div></td>
      <td align="center">&nbsp;</td>
    </tr>
    <tr>
      <td ><span class="Estilo1"></span></td>
      <td >&nbsp;</td>
      <td >&nbsp;</td>
      <td >&nbsp;</td>
      <td colspan="2" ><div align="center"><strong><font size="3" >FECHA</font></strong></div></td>
      <td ><div align="center"><strong><font size="3" ><?php echo $fecha; ?></font></strong></div></td>
    </tr>
  <tr>
    <td colspan="5"  bgcolor="skyblue"><div align="left"><?php echo "Cliente : " .$cdgcli. " - " .$dsccli ; ?></div></td>
    <td  bgcolor="skyblue">&nbsp;</td>
    <td  bgcolor="skyblue"><font size="3" ><?php echo $faccon; ?></font></td>
  </tr>
     
     <tr>
       <td colspan="2"  bgcolor="skyblue"><?php echo "Cédula : " .$cedcli ; ?></td>
       <td  bgcolor="skyblue"><?php echo "Télefono : " .$numtel ; ?></td>
       <td colspan="3"  bgcolor="skyblue"><?php echo "Vendedor : " .$dscven ; ?></td>
       <td  bgcolor="skyblue"><font size="3" ><?php echo $pladia; ?></font></td>
     </tr>
     <tr>
       <td colspan="6"  bgcolor="skyblue"><div align="left"><?php echo "Dirección : " .$dircli ; ?></div></td>
       <td  bgcolor="skyblue">&nbsp;</td>
     </tr>
     <tr>
       <td colspan="7"   border="1"><div align="center"></div></td>
     </tr>
     
  <tr>
    <td width="9%"  align="center"bgcolor="skyblue" ><span class="Estilo29">CODIGO</span></td>
    <td width="9%" align="center" bgcolor="skyblue" ><span class="Estilo29">CANTIDAD</span></td>
    <td width="55%" align="center" bgcolor="skyblue" ><span class="Estilo29">DESCRIPCION</span></td>
    <td width="4%" align="center" bgcolor="skyblue" ><span class="Estilo29">IV</span></td>
	<td width="6%" align="center" bgcolor="skyblue"><span class="Estilo29">DESC.</span></td>
    <td width="8%" align="right" bgcolor="skyblue"><div align="center" class="Estilo29">P/U</div></td> 
	    <td width="9%" align="right" bgcolor="skyblue"><div align="center" class="Estilo29">SUBTOTAL</div></td>
  </tr>
  
<?PHP
		

 
      $consulta=mysql_query("SELECT * FROM proforlineas WHERE  codproforma='$codproforma' ORDER BY numlinea " );
        while($dato=mysql_fetch_array($consulta)){
			
				$dscart =$dato['dscart'];
				$numlinea = $dato['numlinea'];		
				$codigo = $dato['codigo'];
				$impuesto = $dato['impuesto'];
				$cantidad = number_format($dato['cantidad'], 2);
				$dcto = number_format($dato['dcto'], 2);
				$preivi = number_format($dato['preivi'], 2);
				$importe = number_format($dato['importe'], 2);
	
				
	if ($impuesto ==0.00)  {  //  si el articulo no paga impuesto 
	    
      $paga_impuesto="N";

	   }  else  {          ///  si el articulo paga impuesto 

      $paga_impuesto="S";
	     
	    }
	   
				
				

			
			

?>  

 <tr>
   <td align="left"><font size=1 ><?php echo $codigo?></font></td>
   <td align="center"><font size=1 ><?php echo $cantidad?></font></td>
   <td align="left"><font size=1 ><?php echo $dscart?></font></td>
   <td align="center"><font size=1 ><?php echo $paga_impuesto?></font></td>
   <td align="center"><font size=1 ><?php echo $dcto?></font></td>
   <td align="right"><font size=1 ><?php echo $preivi?></font></td>
   <td align="right"><font size=1 ><?php echo $importe ?></font></td>
  </tr>
  
  <?php
	    $contador++;
  	        
		 } 
		 
		 
		 
		 
  ?>
</table>

<table width="92%" height="50" border="0" cellpadding="0" cellspacing="0">

 <tr>
   <td></td>
  </tr>
</table>

    <table width="92%"  border="0" cellspacing="0" cellpadding="0">

 <tr>
  
   <td  width="9%"align="right">&nbsp;</td>
   <td width="9%" align="right">&nbsp;</td>
   <td width="55%" align="right"><div align="center">Validez de la Oferta 8 días </div></td>
   <td width="4%" align="right">&nbsp;</td>
   <td width="6%" align="right">&nbsp;</td>
   <td width="8%" class="Estilo17"><div align="right"><span class="Estilo17">SUBTOTAL</span></div></td>
   <td width="9%"  bgcolor="skyblue" align="right"><span class="Estilo6"><span class="Estilo17"><?php echo number_format($subtot  , 2); ?></span></span></td>
 </tr>
 <tr>
 
   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td class="Estilo17"><div align="right"><span class="Estilo17">DESCUENTO</span></div></td>
   <td align="right"  bgcolor="skyblue"><span class="Estilo6"><span class="Estilo24"><?php echo number_format($destot  , 2); ?></span></span></td>
 </tr>
 <tr>

   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td align="right"><div align="center">____________________________________________</div></td>
   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td class="Estilo17"><div align="right"><span class="Estilo17">IMPUESTO</span></div></td>
   <td align="right"  bgcolor="skyblue"><span class="Estilo6"><span class="Estilo24"><?php echo number_format($impven  , 2); ?></span></span></td>
 </tr>
 <tr>
 
   <td colspan="2" align="right"><div align="center">SELLO</div></td>
   <td align="right"><div align="center">FIRMA</div></td>
   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td class="Estilo17"><div align="right"><span class="Estilo17">TOTAL</span></div></td>
   <td align="right"   bgcolor="skyblue"><span class="Estilo6"><span class="Estilo24"><?php echo number_format($totalproforma  , 2); ?></span></span></td>
 </tr>
</table>


</body>
</html>