<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=informe venta 3327.xls");
header("Pragma: no-cache");
header("Expires: 0");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Informe  Compras 3327</title>
<?
include("../conex.php");

	$periodo = $_POST["txtfecha"];
$dia=substr($periodo,0,2);
 $semestre = substr($periodo,3,2);
	   $anual = substr($periodo,6,4);
	
	$inicio = $anual.'/'.$semestre.'/01';
	 $final = $anual.'/'.$semestre.'/'.$dia;

?>
<style type="text/css">
<!--
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;}
.Estilo2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color:#FF0000}
-->
</style>
</head>
<body LINK="#FFFFFF" VLINK="#FFFFFF" ALINK="#FFFFFF">
<table width="900" border="0">
	<form name="form1" method="post" action="">
      <tr>
        <th width="50%"><div align="right">
            <input name="salir" type="button" class="Estilo1" id="salir" value="Salir" onclick="cerrar()"/>
        </div></th>
  <th width="50%"><div align="left">
			<input name="imprimir" type="button" class="Estilo1" id="imprimir" value="Imprimir" onclick="imprimir()"/>
        </div></th>
      <th width="50%"><div align="left">
			Periodo  <?=$inicio;?>   <?=$final;?>
        </div></th> 
      </tr>
        </form>
    </table>
    
<table width="921" border="0" >
<tr bgcolor="#CCCCCC" >
 <th width="76" scope="col"><div align="center">Tipo Doc</div></th>
    <th width="76" scope="col"><div align="center">Folio</div></th>
  	<th width="90" scope="col"><div align="center">Rut Contraparte</div></th>
    <th width="76" scope="col"><div align="center">Tasa Impuesto</div></th>
    <th width="150" scope="col"><div align="center">Nombre o Razon Social</div></th>
     <th width="150" scope="col"><div align="center">Tipo Impuesto[1=IVA:2=LEY 18211]</div></th>
    <th width="150" scope="col"><div align="center">Anulado[A]</div></th>
    <th width="76" scope="col"><div align="center">Fecha de Emision del Documento</div></th>
    <th width="76" scope="col"><div align="center">Monto Exento</div></th>
    <th width="76" scope="col"><div align="center">Monto Neto</div></th>
    
    <th width="76" scope="col"><div align="center">Monto IVA Recuperable</div></th>
      <th width="76" scope="col"><div align="center">Cod IVA no Rec</div></th>
      <th width="76" scope="col"><div align="center">Monto IVA no Rec</div></th>
        <th width="76" scope="col"><div align="center">IVA Uso Común</div></th>
          <th width="76" scope="col"><div align="center">Cod Otro Imp (Con Crédito)</div></th>
            <th width="76" scope="col"><div align="center">Tasa Otro Imp (Con Crédito)</div></th>
              <th width="76" scope="col"><div align="center">Monto Otro Imp (Con Crédito)</div></th>
                <th width="76" scope="col"><div align="center">Monto Otro Imp Sin Crédito</div></th>
                  <th width="76" scope="col"><div align="center">Monto Activo Fijo</div></th>
                    <th width="76" scope="col"><div align="center">Monto IVA Activo Fijo</div></th>
                    
    <th width="76" scope="col"><div align="center">IVA No Retenido</div></th>           
     <th width="76" scope="col"><div align="center">Tabacos - Puros</div></th>
      <th width="76" scope="col"><div align="center">Tabacos - Cigarrillos</div></th>
        <th width="76" scope="col"><div align="center">Tabacos - Elaborados</div></th>
          <th width="76" scope="col"><div align="center">Impuesto a Vehiculos Automóviles</div></th>
            <th width="76" scope="col"><div align="center">Codigo sucursal SII</div></th>
              <th width="76" scope="col"><div align="center">Numero Interno</div></th>
                <th width="76" scope="col"><div align="center">Emisor/Receptor</div></th>
                  <th width="76" scope="col"><div align="center">Monto Total</div></th>
  
				      
  </tr>
  
  <?
  
  $sqlfs =  "SELECT * FROM entrada WHERE fecha_emision>='$inicio' AND fecha_emision<='$final' AND (tipo_dcto=2 OR tipo_dcto=6 OR tipo_dcto=7) AND empresa = $id_empresa ORDER BY num_dcto";
			
		  	$resfs = mysql_query($sqlfs,$enlace);	
			$cont=0;
			while (mysql_fetch_object ($resfs))
				{
				$fecha = mysql_result($resfs, $cont, "fecha_emision");
				$dia = substr ($fecha, 8, 2);
				$mes = substr ($fecha, 5, 2);
				$ano = substr ($fecha, 0, 4);
			$fecha=$dia."/".$mes."/".$ano;
				$iddcto = mysql_result($resfs, $cont, "tipo_dcto");
				if($iddcto==1)$dcto='B';
				if($iddcto==2)$dcto='30';
				if($iddcto==3)$dcto='NV';
				if($iddcto==4)$dcto='C';
				if($iddcto==5)$dcto='G';
				if($iddcto==6)$dcto='60';
				if($iddcto==7)$dcto='55';
				
				
                if($iddcto==8)$dcto='F C';
				if($iddcto==14)$dcto='33';
				if($iddcto==15)$dcto='NC E';
				if($iddcto==16)$dcto='ND E';
				
				$nombre = "NN";
				
				$rut = mysql_result($resfs, $cont, "rut_proveedor");
				if ($rut!='')
				{
					
					$sqlc = "SELECT * FROM nombres WHERE rut='$rut'";
					$resc = mysql_query($sqlc,$enlace);
					$nombre = mysql_result($resc, 0, "razon_social");
				}
				else 
					{
					$nombre = "Boleta";
					$rut="&nbsp;";
					
					}
				$nro = mysql_result($resfs, $cont, "num_dcto");
				
				$exento= mysql_result($resfs, $cont, "exento");
				$total_exento+=$exento;
				$exento=number_format($exento,0,',','.');
				
				$iva = mysql_result($resfs, $cont, "iva");
				$total_iva+=$iva;
				$iva=number_format($iva,0,',','.');
				
				$neto= mysql_result($resfs, $cont, "neto");
				$total_neto+=$neto;
				$neto=number_format($neto,0,',','.');
				
				$total = mysql_result($resfs, $cont, "total");
				$total_total+=$total;
				$total=number_format($total,0,',','.');
				
		  	?>
			<tr>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$dcto?></strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$nro?></strong></span></div></td>
              <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong><?=$rut?></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong>19</strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong><?=$nombre?></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
			  <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong><?=$fecha?></strong></span></div></td>
              <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong><?=$exento?> </strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong><?=$neto?> </strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong><?=$iva?></strong></span></div></td>
                
                
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                
                 <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
              
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
      
                 <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
      
                
			  <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong><?=$total?> </strong></span></div></td>
				
	        </tr>	
			<?
			$cont+=1;
			}
		
			?>
            
			

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

<script language="javascript" type="text/javascript">

function cerrar()
{
window.top.open('','_parent','');
window.top.close();
}

function imprimir()
{
document.getElementById('salir').style.display = "none";
document.getElementById('imprimir').style.display = "none";
window.print();
document.getElementById('salir').style.display = "block";
document.getElementById('imprimir').style.display = "block";
}

</script>