<?php

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

 include ("../conexion.php");	
 
   

       $parametros = "SELECT * FROM web_0000 ";
       $result_parametros = $mysqli->query($parametros);
       $row_para = $result_parametros->fetch_array();
     
	   $NombreComercial =  $row_para["NOMCOM"];
	   $Razon           =  $row_para["RAZSOC"];
	   $Direccion       =  $row_para["DIREMP"];
	   $Cedula          =  $row_para["CEDJUR"];
	   $Telefono        =  $row_para["NUMTEL"];

	 $fecini    = $_GET["fechainicio"];
	 $fecfin    = $_GET["fechafin"];
	 $cdgtipven = $_GET["combotipoventa"];
	 $cdgtipcxp=  $_GET["combotipocxp"];
	 

	$exento        = 0  ;
	$gravado       = 0 ;
	$subtotal      = 0 ;
	$descuento     = 0  ;
	$impuesto      = 0 ;
	$total         = 0  ;
	 
	 $fechainicio= implode("-", array_reverse(explode("-", $fecini))); 
 	 $fechafin= implode("-", array_reverse(explode("-", $fecfin))); 
	
	$where="1=1";
if ($cdgtipven <> "") { $where.=" AND  web_2201.cdgtipven='$cdgtipven'"; }
if ($cdgtipcxp <> "") { $where.=" AND  web_2201.cdgtipcxp='$cdgtipcxp'"; }

if (($fechainicio<>"") and ($fechafin<>"")) {
	$where.=" AND web_2201.fecpro between '".$fechainicio."' AND '".$fechafin."'";
} else {
	if ($fechainicio<>"") {
		$where.=" and  web_2201.fecpro >='".$fechainicio."'";
	} else {
		if ($fechafin<>"") {
			$where.=" and  web_2201.fecpro <='".$fechafin."'";
		}
	}
}



	 
 $fechainicio= implode("-", array_reverse(explode("-", $fecini))); 
 $fechafin= implode("-", array_reverse(explode("-", $fecfin))); 

//$where.=" ORDER BY fecpro ASC";					
if ($cdgtipcxp=="") {
	 
	$dsccxp="TODAS LAS CUENTAS";
	 
	     } else {

	   $query_tipocxp="SELECT * FROM tipo_cxp WHERE cdgcxp=$cdgtipcxp ";
       $resultado = $mysqli->query($query_tipocxp);
       $row = $resultado->fetch_array();
	   
	   $dsccxp    = $row["dsccxp"];
	        }	
?>
<!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}
-->
</style>
</head>
<body>
<table width="92%" border="0" cellspacing="0" cellpadding="0">
    
     <tr>
      <td><div align="center"></div></td>
      <td colspan="14"  ><div align="center"><font size=8 ><?php echo $NombreComercial?></font></div>
      <div align="center"></div><div align="center"></div></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="14" ><div align="center"><font size="3" ><?php echo $Razon?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="14" ><div align="center"><font size="2" ><?php echo $Cedula; ?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="14" ><div align="center"><font size="2" ><?php echo $Direccion; ?></font></div></td>
    </tr>
    <tr>
      <td><div align="center"></div></td>
      <td colspan="14" ><div align="center"><font size="2" ><?php echo $Telefono; ?></font></div></td>
    </tr>
    <tr>
      <td><span class="Estilo1"></span></td>
      <td colspan="14" ><span class="Estilo1"></span></td>
    </tr>
  <tr>
     <td></td>
 <td colspan="14"  bgcolor="skyblue"><div align="center"><strong><font size="3"> Reporte Analitico  <?php echo $dsccxp; ?> </font></strong></div></td>
  </tr>
     
     <tr>
       <td></td>
       <td colspan="14"   border="1"><div align="center"><font size="3" >Fecha del <?php echo $fecini; ?> Al <?php echo $fecfin; ?></font></div></td>
     </tr>
     <tr>
       <td></td>
    
	<td colspan="15"   border="1"></td>
	<td colspan="8" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Tarifa Reducida</strong></font></span></td>		
	
	<td width="20%" align="center" ><span class="Estilo4"><strong></strong></font></span></td>
	
    <td colspan="6" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Tarifa Transitoria</strong></font></span></td>		
    <td width="20%" align="center" ><span class="Estilo4"><strong></strong></font></span></td>
   	 

	<td colspan="2" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Tarifa General</strong></font></span></td>		
	

  <tr>
  <tr>
      <td width="1%"></td>

    <td width="20%"  align="center"bgcolor="skyblue" ><strong>Factura</strong></font></td>
    <td width="20%" align="center" bgcolor="skyblue" ><strong>Codigo</strong></font></td>
    <td width="20%" align="center" bgcolor="skyblue" ><strong>Proveedor</strong></font></td>
    <td width="20%" align="center" bgcolor="skyblue" ><strong>Fecha</strong></font></td>
    <td width="20%" align="center" bgcolor="skyblue"><strong>F.Proceso</strong></font></td>
	<td width="20%" align="center" bgcolor="skyblue"><strong>Plazo</strong></font></td>
    <td width="20%" align="right" bgcolor="skyblue"><strong>Sub.Exento </strong></font></td> 
	    <td width="20%" align="right" bgcolor="skyblue"><strong>Sub.Gravado </strong></font></td>
	    <td width="20%" align="right" bgcolor="skyblue"><strong>Subtotal </strong></font></td>
        <td width="20%" align="right" bgcolor="skyblue"><strong>Descuento </strong></font></td>
		<td width="20%" align="right" bgcolor="skyblue"><strong>Impuesto </strong></font></td>
        <td width="20%" align="right" bgcolor="skyblue"><strong>Flete </strong></font></td>
        <td width="20%" align="right" bgcolor="skyblue"><strong>Otros </strong></font></td>
        <td width="20%" align="right" bgcolor="skyblue"><strong>Total </strong></font></td>
        
        <td width="20%" align="center" ><span class="Estilo4"><strong></strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 0%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 0%</strong></font></span></td>	
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 1%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 1%</strong></font></span></td>	
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 2%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 2%</strong></font></span></td>	
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 4%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 4%</strong></font></span></td>	
	
	<td width="20%" align="center" ><span class="Estilo4"><strong></strong></font></span></td>
   	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 0%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 0%</strong></font></span></td>	
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 4%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 4%</strong></font></span></td>	
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 8%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 8%</strong></font></span></td>	
   
    <td width="20%" align="center" ><span class="Estilo4"><strong></strong></font></span></td>
   	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal 13%</strong></font></span></td>		
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto 13%</strong></font></span></td>	
  </tr>
  
  
<?PHP
	  /*Impuestos TOTALES*/
	  $TOTAL_I0R =  0 ;
	  $TOTAL_I1R =  0 ;
	  $TOTAL_I2R =  0 ;
	  $TOTAL_I4R =  0 ;
	  $TOTAL_I0T =  0 ;
	  $TOTAL_I4T =  0 ;
	  $TOTAL_I8T =  0 ;
	  $TOTAL_I13 =  0 ;
	  
	  	   /*Subtotales TOTALES*/
	  $SUBTOTAL_I0R =  0 ;
	  $SUBTOTAL_I1R =  0 ;
	  $SUBTOTAL_I2R =  0 ;
	  $SUBTOTAL_I4R =  0 ;
	  $SUBTOTAL_I0T =  0 ;
	  $SUBTOTAL_I4T =  0 ;
	  $SUBTOTAL_I8T =  0 ;
	  $SUBTOTAL_I13 =  0;		 

				
$consulta= "SELECT  *  FROM web_2201,proveedores WHERE web_2201.cdgpro=proveedores.cdgpro AND web_2201.borrado=0   AND ".$where. "  ORDER BY web_2201.dscpro,web_2201.fecfac ASC " ;
		if ($resultado = $mysqli->query($consulta)) 

 
  		while ($fila = $resultado->fetch_assoc()) {
	
        $fecpro        = $fila["fecpro"];
		$fecpro        = implode("-", array_reverse(explode("-", $fecpro)));
        $fecfac        = $fila["fecfac"];
		$fecfac        = implode("-", array_reverse(explode("-", $fecfac)));
		$numfac        = $fila["numfac"];
		$codfactura    = $fila["codfactura"];
		$cdgpro        = $fila["cdgpro"];
		$cdgpro        = sprintf("%04d",$cdgpro); 
		$dscpro        = $fila["dscpro"];
		$dscpro        = substr($dscpro, 0, 45);
		$pladia        = $fila["pladia"];
		$subexe        = number_format($fila["subexe"], 2);
		$subgra        = number_format($fila["subgra"], 2);
		$totfac        = number_format($fila["totfac"], 2);
		$subfac        = number_format($fila["subfac"], 2);
		$flefac        = number_format($fila["flefac"], 2);
		$impfac        = number_format($fila["impfac"], 2);
		$otrfac        = number_format($fila["otrfac"], 2);
		$desfactot     = number_format($fila["desfactot"], 2);

		/*Impuestos*/
	  $IMP_I0R =  0 ;
	  $IMP_I1R =  0 ;
	  $IMP_I2R =  0 ;
	  $IMP_I4R =  0 ;
	  $IMP_I0T =  0 ;
	  $IMP_I4T =  0 ;
	  $IMP_I8T =  0 ;
	  $IMP_I13 =  0;
	  
	   /*Subtotales*/
	  $SUB_TOTAL_I0R =  0 ;
	  $SUB_TOTAL_I1R =  0 ;
	  $SUB_TOTAL_I2R =  0 ;
	  $SUB_TOTAL_I4R =  0 ;
	  $SUB_TOTAL_I0T =  0 ;
	  $SUB_TOTAL_I4T =  0 ;
	  $SUB_TOTAL_I8T =  0 ;
	  $SUB_TOTAL_I13 =  0;	
	  
	   $compras = "SELECT * FROM facturas_compras WHERE   numfac = '$numfac'  AND  cdgpro = '$cdgpro'  ";
       $result_compras = $mysqli->query($compras);
       $row_compras = $result_compras->fetch_array();
     
	   $codfactura =  $row_compras["codfactura"];
	   
	       $consulta4= ("SELECT codfactura, implin, cdgtar, cdgimp,importe FROM factulinea_compra WHERE  codfactura = '$codfactura' AND cdgimp = '1' ");

	if ($resultado4 = $mysqli->query($consulta4)) 

	 
  	 while ($dato4 = $resultado4->fetch_assoc()) {
		 								
				         	/*Impuestos*/
	 $I0R =  0;
	 $I1R =  0;
	 $I2R =  0;
	 $I4R =  0;
	 $I0T =  0;
	 $I4T =  0;
	 $I8T =  0;
	 $I13 =  0;
	  /*Subtotales*/
	 $SUB0R =  0;
	 $SUB1R =  0;
	 $SUB2R =  0;
	 $SUB4R =  0;
	 $SUB0T =  0;
	 $SUB4T =  0;
	 $SUB8T =  0;
	 $SUB13 =  0;
					
						$cdgtar        = $dato4["cdgtar"];
						//$SubTotal      = $dato4["subfac"];
						$SubTotal   = $dato4["importe"];
						$impuesto      = $dato4["implin"];
	
						     if ($cdgtar == "01") { $I0R =  $impuesto; $SUB0R = $SubTotal;
						}elseif ($cdgtar == "02") { $I1R =  $impuesto; $SUB1R = $SubTotal;
						}elseif ($cdgtar == "03") { $I2R =  $impuesto; $SUB2R = $SubTotal;
						}elseif ($cdgtar == "04") { $I4R =  $impuesto; $SUB4R = $SubTotal;
						}elseif ($cdgtar == "05") { $I0T =  $impuesto; $SUB0T = $SubTotal;
						}elseif ($cdgtar == "06") { $I4T =  $impuesto; $SUB4T = $SubTotal;
						}elseif ($cdgtar == "07") { $I8T =  $impuesto; $SUB8T = $SubTotal;
						}elseif ($cdgtar == "08") { $I13 =  $impuesto; $SUB13 = $SubTotal;
						}
						
						   /*Impuestos*/
						  $IMP_I0R =  $IMP_I0R + $I0R ;
						  $IMP_I1R =  $IMP_I1R + $I1R ;
						  $IMP_I2R =  $IMP_I2R + $I2R ;
						  $IMP_I4R =  $IMP_I4R + $I4R ;
						  $IMP_I0T =  $IMP_I0T + $I0T ;
						  $IMP_I4T =  $IMP_I4T + $I4T ;
						  $IMP_I8T =  $IMP_I8T + $I8T ;
						  $IMP_I13 =  $IMP_I13 + $I13 ;	 
					
							   /*Subtotales*/
						  $SUB_TOTAL_I0R =  $SUB_TOTAL_I0R + $SUB0R;
						  $SUB_TOTAL_I1R =  $SUB_TOTAL_I1R + $SUB1R;
						  $SUB_TOTAL_I2R =  $SUB_TOTAL_I2R + $SUB2R;
						  $SUB_TOTAL_I4R =  $SUB_TOTAL_I4R + $SUB4R;
						  $SUB_TOTAL_I0T =  $SUB_TOTAL_I0T + $SUB0T;
						  $SUB_TOTAL_I4T =  $SUB_TOTAL_I4T + $SUB4T;
						  $SUB_TOTAL_I8T =  $SUB_TOTAL_I8T + $SUB8T;
						  $SUB_TOTAL_I13 =  $SUB_TOTAL_I13 + $SUB13;
						  
						  
						  
						  		   /*Impuestos TOTALES*/
						  $TOTAL_I0R =  $TOTAL_I0R + $I0R ;
						  $TOTAL_I1R =  $TOTAL_I1R + $I1R ;
						  $TOTAL_I2R =  $TOTAL_I2R + $I2R ;
						  $TOTAL_I4R =  $TOTAL_I4R + $I4R ;
						  $TOTAL_I0T =  $TOTAL_I0T + $I0T ;
						  $TOTAL_I4T =  $TOTAL_I4T + $I4T ;
						  $TOTAL_I8T =  $TOTAL_I8T + $I8T ;
						  $TOTAL_I13 =  $TOTAL_I13 + $I13 ;	 
					
							   /*Subtotales TOTALES*/
						  $SUBTOTAL_I0R =  $SUBTOTAL_I0R + $SUB0R;
						  $SUBTOTAL_I1R =  $SUBTOTAL_I1R + $SUB1R;
						  $SUBTOTAL_I2R =  $SUBTOTAL_I2R + $SUB2R;
						  $SUBTOTAL_I4R =  $SUBTOTAL_I4R + $SUB4R;
						  $SUBTOTAL_I0T =  $SUBTOTAL_I0T + $SUB0T;
						  $SUBTOTAL_I4T =  $SUBTOTAL_I4T + $SUB4T;
						  $SUBTOTAL_I8T =  $SUBTOTAL_I8T + $SUB8T;
						  $SUBTOTAL_I13 =  $SUBTOTAL_I13 + $SUB13;
						  
						  }

?>  

 <tr>
   <td></td>
   <td align="left"><font size=1 ><?php echo "N. ".$numfac?></font></td>
   <td align="center"><font size=1 ><?php echo $cdgpro?></font></td>
   <td align="left"><font size=1 ><?php echo $dscpro?></font></td>
   <td align="center"><font size=1 ><?php echo $fecfac?></font></td>
   <td align="center"><font size=1 ><?php echo $fecpro?></font></td>
   <td align="center"><font size=1 ><?php echo $pladia?></font></td>
   <td align="right"><font size=1 ><?php echo $subexe?></font></td>
   <td align="right"><font size=1 ><?php echo $subgra?></font></td>
   <td align="right"><font size=1 ><?php echo $subfac?></font></td>
   <td align="right"><font size=1 ><?php echo $desfactot?></font></td>
   <td align="right"><font size=1 ><?php echo $impfac?></font></td>
   <td align="right"><font size=1 ><?php echo $flefac?></font></td>
   <td align="right"><font size=1 ><?php echo $otrfac?></font></td>
   <td align="right"><font size=1 ><?php echo $totfac?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I0R,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I0R,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I1R,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I1R,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I2R,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I2R,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I4R,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I4R,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I0T,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I0T,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I4T,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I4T,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I8T,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I8T,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($SUB_TOTAL_I13,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($IMP_I13,2) ?></font></td>
 </tr>
  
  <?php
	
		 } 
		 

	  
      $consulta2= ("SELECT SUM(totfac) AS total , SUM(subfac) AS subtotal, SUM(desfactot) AS descuento , SUM(impfac) AS impuesto , SUM(flefac) AS flete, SUM(otrfac) AS otros, SUM(subexe) AS subexento, SUM(subgra) AS subgravado FROM web_2201 WHERE borrado=0 AND ".$where
				);

	if ($resultado2 = $mysqli->query($consulta2)) 

  	 while ($dato = $resultado2->fetch_assoc()) {

				$subexento    = $dato['subexento'];
				$subgravado   = $dato['subgravado'];
				$subtotal     = $dato['subtotal'];
				$descuento    = $dato['descuento'];
				$impuesto     = $dato['impuesto'];
				$total        = $dato['total'];
				$flete        = $dato['flete'];
				$otros        = $dato['otros'];
	 } 		
  
		 
  ?>
</table>

</table>




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

 <tr>
   <td></td>
   <td align="left">&nbsp;</td>
   <td align="center">&nbsp;</td>
   <td align="left">&nbsp;</td>
   <td align="center">&nbsp;</td>
   <td align="center">&nbsp;</td>
   <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 align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
   <td align="right">&nbsp;</td>
 </tr>
 <tr>

     <td width="1%"></td>
      <td align="left"><strong><font size=1 >TOTALES</font></strong></td>
   <td align="center"><strong><font size=1 ></font></strong></td>
   <td align="left"><strong><font size=1 ></font></strong></td>
   <td align="center"><strong><font size=1 ></font></strong></td>
   <td align="center"><strong><font size=1 ></font></strong></td>
    <td align="center"><strong><font size=1 ></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subexento , 2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subgravado , 2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotal , 2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($descuento , 2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($impuesto , 2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format( $flete , 2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($otros , 2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($total , 2) ?></font></strong></td>
 </tr>
</table>


<?php	
	/////////////////////////////////////////////////////////////////  CALCULA TARIFAS FACTURACION  ///////////////////////////////////////

$consulta3= ("SELECT  *  FROM web_2201,proveedores WHERE web_2201.cdgpro=proveedores.cdgpro AND web_2201.borrado=0   AND ".$where. "  ORDER BY web_2201.dscpro,web_2201.fecfac ASC" );
	  $TOTAL_I0R =  0 ;
	  $TOTAL_I1R =  0 ;
	  $TOTAL_I2R = 0 ;
	  $TOTAL_I4R =  0 ;
	  $TOTAL_I0T =  0 ;
	  $TOTAL_I4T =  0 ;
	  $TOTAL_I8T =  0 ;
	  $TOTAL_I13 =  0 ;
	  
	if ($resultado3 = $mysqli->query($consulta3)) 


  	 while ($dato3 = $resultado3->fetch_assoc()) {			
	 $numfac   = $dato3['numfac'];
	 $cdgpro   = $dato3['cdgpro'];


       $compras = "SELECT * FROM facturas_compras WHERE   numfac = '$numfac'  AND  cdgpro = '$cdgpro'  ";
       $result_compras = $mysqli->query($compras);
       $row_compras = $result_compras->fetch_array();
     
	   $codfactura =  $row_compras["codfactura"];


    $consulta4= ("SELECT codfactura, implin, cdgtar, cdgimp FROM factulinea_compra WHERE  codfactura = '$codfactura' AND cdgimp = '1' ");

	if ($resultado4 = $mysqli->query($consulta4)) 

	 
  	 while ($dato4 = $resultado4->fetch_assoc()) {
	 $I0R =  0;
	 $I1R =  0;
	 $I2R =  0;
	 $I4R =  0;
	 $I0T =  0;
	 $I4T =  0;
	 $I8T =  0;
	 $I13 =  0;

				$impuesto    = $dato4['implin'];
			  	$cdgtar      = $dato4['cdgtar'];
		
	     if ($cdgtar == "01") {	$I0R =  $impuesto;
	}elseif ($cdgtar == "02") { $I1R =  $impuesto;
	}elseif ($cdgtar == "03") { $I2R =  $impuesto;
	}elseif ($cdgtar == "04") { $I4R =  $impuesto;
	}elseif ($cdgtar == "05") { $I0T =  $impuesto;
	}elseif ($cdgtar == "06") { $I4T =  $impuesto;
	}elseif ($cdgtar == "07") { $I8T =  $impuesto;
	}elseif ($cdgtar == "08") { $I13 =  $impuesto;
	} 
	
	  $TOTAL_I0R =  $TOTAL_I0R + $I0R ;
	  $TOTAL_I1R =  $TOTAL_I1R + $I1R ;
	  $TOTAL_I2R =  $TOTAL_I2R + $I2R ;
	  $TOTAL_I4R =  $TOTAL_I4R + $I4R ;
	  $TOTAL_I0T =  $TOTAL_I0T + $I0T ;
	  $TOTAL_I4T =  $TOTAL_I4T + $I4T ;
	  $TOTAL_I8T =  $TOTAL_I8T + $I8T ;
	  $TOTAL_I13 =  $TOTAL_I13 + $I13 ;
	
		
	 } 		
	


	 } 		




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

 <tr>
   <td></td>
   <td align="left">&nbsp;</td>
   <td align="center">&nbsp;</td>
   <td align="left">&nbsp;</td>
   <td align="center">&nbsp;</td>
   <td align="center">&nbsp;</td>
   <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 align="right">&nbsp;</td>
 </tr>
 <tr>
   <td></td>
   <td align="left">&nbsp;</td>
   <td colspan="4" align="center"  bgcolor="#33CC66" >REDUCIDA</td>
   <td align="center">&nbsp;</td>
   <td colspan="3" align="center" bgcolor="#33CC66"  >TRANSITORIO</td>
   <td align="right">&nbsp;</td>
   <td align="right" bgcolor="#33CC66" >GENERAL</td>
 </tr>
 <tr>
   <td class="Estilo17"></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo17">0%</td>
   <td align="right" class="Estilo17">1 % </td>
   <td align="right" class="Estilo17">2 % </td>
   <td align="right" class="Estilo17">4 % </td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6">0%</td>
   <td align="right" class="Estilo6">4 % </td>
   <td align="right" class="Estilo6">8 %</td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6">13 %</td>
 </tr>

 <tr>

   <td width="1%" class="Estilo17"></td>
   <td align="left" class="Estilo6">IMPUESTO FACTURAS </td>
   <td align="right" class="Estilo17"><?php echo number_format($TOTAL_I0R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($TOTAL_I1R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($TOTAL_I2R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($TOTAL_I4R  , 2);?></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($TOTAL_I0T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($TOTAL_I4T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($TOTAL_I8T  , 2);?></span></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($TOTAL_I13  , 2);?></span></td>
 </tr>
</table>

	

</body>
</html>