<?php

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Reporte_Facturacion.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"];
	 $cdgcaj    = $_GET["cdgcaj"];
	 $cdgcli    = $_GET["cdgcli"];
	 $dsccli    = $_GET["dsccli"];
	 
	 
	$exento_tot    = 0;
	$gravado_tot   = 0;
	$subtotal_tot  = 0;
	$descuento_tot = 0;
	$impuesto_tot  = 0;
	$total_tot     = 0;
    $where_notas   = "";
    $where         = "";
	$exento_fac    = 0;
	$gravado_fac   = 0;
	$subtotal_fac  = 0;
	$descuento_fac = 0;
	$impuesto_fac  = 0;
	$total_fac     = 0;	 
	$exento        = 0  ;
	$gravado       = 0 ;
	$subtotal      = 0 ;
	$descuento     = 0  ;
	$impuesto      = 0 ;
	$total         = 0  ;
	
	$totexento_fac 	 = 0  ;
	$totexento_not   = 0  ;
	$totexento_deb   = 0  ;
	$totexonerado_fac   = 0  ;
	$totexonerado_not   = 0  ;
	$totexonerado_deb   = 0  ;
	$totgravado_fac  = 0  ;
	$totgravado_not  = 0  ;
	$totgravado_deb  = 0  ;
	
	$totnosujeto_fac   = 0  ; 
	$totnosujeto_not = 0  ; 
	$totnosujeto_deb = 0  ; 
				
				
				
				
	
	
		 	 /////////////////        where para facturas  y notas ********************
	 
	if ($cdgtipven <> "") { $where.=" AND cdgtipven='$cdgtipven'"; }

	 
	
	
	 	 /////////////////        where para facturas ********************
	 
	if ($cdgcaj <> "") { $where.=" AND cdgcaj='$cdgcaj'"; }
	if ($cdgcli<> "") { $where.=" AND cdgcli='$cdgcli'"; }
	if ($dsccli<> "") { $where.=" AND dsccli like '%$dsccli%'"; }	
	 $where.=" ORDER BY numfactura ASC";
	 
	 
	 /////////////////        where para notas de credito ********************
	 
	 
	 if ($cdgcaj <> "") { $where_notas.=" AND cdgcaj='$cdgcaj'"; }
	 if ($cdgcli<> "") { $where_notas.=" AND cdgcli='$cdgcli'"; }
	 if ($dsccli<> "") { $where_notas.=" AND dsccli like '%$dsccli%'"; }	
	 $where_notas.=" ORDER BY numcomp ASC";
	 
	 
	 
 $fechainicio= implode("-", array_reverse(explode("-", $fecini))); 
 $fechafin= implode("-", array_reverse(explode("-", $fecfin))); 


 if ($cdgcaj=="") {
	 
	 $nomcomusu="TODOS LOS CAJEROS";
	 
	     } else {


	   $query_codcaj="SELECT * FROM usuarios  WHERE codusu=$cdgcaj ";
       $resultado = $mysqli->query( $query_codcaj);
       $row = $resultado->fetch_array();
        
		$nomcomusu    = $row["nomcomusu"];
     }
					
?>
<!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}
.Estilo4 {font-size: medium}
.Estilo6 {
	color: #000000;
	font-weight: bold;
}
.Estilo17 {color: #000000; font-weight: bold; font-size: 14px; }
-->
</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 de Facturación</font>  </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; ?> -  <?php echo $nomcomusu; ?></font></div></td>
     </tr>
        <tr>
       <td></td>
    
	
	
	
		<td colspan="15"   border="1">FACTURAS DOLARES</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" ><span class="Estilo4"><strong>Factura</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Codigo</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Cliente</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Plazo</strong></font></span></td>
    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exento </strong></font></span></td> 
	<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exonerado </strong></font></span></td>
	 <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.NoSujeto </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Gravado </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Subtotal </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Descuento </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Impuesto </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Imp. Servicio </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Total </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 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 facturas WHERE  fecha  between '$fechainicio' AND '$fechafin' AND tipmoneda='USD'  ".$where;
		
	//echo  $consulta;
		if ($resultado = $mysqli->query($consulta)) 

	
	  
 
  		while ($fila = $resultado->fetch_assoc()) {
	
        $fecha         = $fila["fecha"];
		$fecha         = implode("-", array_reverse(explode("-", $fecha)));
		$numfactura    = $fila["numfactura"];
		$numfactura    = substr($numfactura  , 10, 10);
		$codfactura    = $fila["codfactura"];
		$cdgcli        = $fila["cdgcli"];
		$cdgcli        = sprintf("%04d",$cdgcli); 
		$dsccli        = $fila["dsccli"];
		$dsccli        = substr($dsccli, 0, 40);
		$pladia        = $fila["pladia"];
		$totalfactura  = number_format($fila["totalfactura"], 2);
		$subexe        = number_format($fila["subexe"], 2);
		$subgra        = number_format($fila["subgra"], 2);
		$subtot        = number_format($fila["subtot"], 2);
		$impven        = number_format($fila["impven"], 2);
		$destot        = number_format($fila["destot"], 2);
		$otrcar        = number_format($fila["otrcar"], 2);
		
		$totgravado     = number_format($fila["totgravado"], 2);
		$totexento     = number_format($fila["totexento"], 2);
		$totexonerado     = number_format($fila["totexonerado"], 2);
		$totnosujeto     = number_format($fila["totnosujeto"], 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;

	  


	 
	 	 if ($impven >0){   // si el impuesto es mayor a 0
		 
					$consulta2= "SELECT * FROM factulinea WHERE  codfactura =  '$codfactura'   ";
						if ($resultado2 = $mysqli->query($consulta2)) 
				

						while ($fila2 = $resultado2->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        = $fila2["cdgtar"];
						$SubTotal      = $fila2["subtotal"];
						$impuesto      = $fila2["impuesto"];
	
						     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 $numfactura?></font></td>
   <td align="center"><font size=1 ><?php echo $cdgcli?></font></td>
   <td align="left"><font size=1 ><?php echo $dsccli?></font></td>
   <td align="center"><font size=1 ><?php echo $fecha?></font></td>
   <td align="center"><font size=1 ><?php echo $pladia?></font></td>
   <td align="right"><font size=1 ><?php echo $totexento?></font></td>
   <td align="right"><font size=1 ><?php echo $totexonerado ?></font></td>
      <td align="right"><font size=1 ><?php echo $totnosujeto ?></font></td>
   <td align="right"><font size=1 ><?php echo $totgravado ?></font></td>
   <td align="right"><font size=1 ><?php echo  $subtot ?></font></td>
   <td align="right"><font size=1 ><?php echo $destot?></font></td>
   <td align="right"><font size=1 ><?php echo $impven ?></font></td>
   <td align="right"><font size=1 ><?php echo $otrcar ?></font></td>
   <td align="right"><font size=1 ><?php echo $totalfactura ?></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(totalfactura) AS total , SUM(subtot) AS subtotal, SUM(subexe) AS exento, SUM(subgra) AS gravado, SUM(totnosujeto) AS totnosujeto, SUM(destot) AS descuento , SUM(impven) AS impuesto, SUM(totexento) AS  totexento, SUM(totexonerado) AS  totexonerado, SUM(totgravado) AS  totgravado , SUM(otrcar) AS  total_otrcar FROM facturas WHERE  fecha  between '$fechainicio' AND '$fechafin' AND tipmoneda='USD' ".$where );

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

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

				$exento_fac    = $dato['exento'];
				$gravado_fac   = $dato['gravado'];
				$subtotal_fac  = $dato['subtotal'];
				$descuento_fac = $dato['descuento'];
				$impuesto_fac  = $dato['impuesto'];
				$otrcar_fac  = $dato['total_otrcar'];
				$total_fac     = $dato['total'];
				
				$totgravado_fac   = $dato['totgravado'];
				$totexento_fac    = $dato['totexento'];
				$totexonerado_fac    = $dato['totexonerado'];
				$totnosujeto_fac    = $dato['totnosujeto'];
				
				
				
				
	 } 		
  
  ?>
  
</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>
 </tr>
 <tr>

     <td width="1%"></td>
      <td align="left"><strong><font size=1 >TOTAL FACTURAS DOLARES </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="right"><strong><font size=1 ><?php echo number_format($totexento_fac , 2);?></font></strong></td>
      <td align="right"><strong><font size=1 ><?php echo number_format($totexonerado_fac , 2);?></font></strong></td>
	     <td align="right"><strong><font size=1 ><?php echo number_format($totnosujeto_fac, 2); ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($totgravado_fac, 2); ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotal_fac , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($descuento_fac , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($impuesto_fac , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($otrcar_fac  , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($total_fac , 2); ?></font></strong></td>
 </tr>
</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>
 </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">SUBTOTAL </td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I0R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I1R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I2R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I4R  , 2);?></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I0T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I4T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I8T  , 2);?></span></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I13  , 2);?></span></td>

   </tr>
   
    <tr>
	 <td width="1%" class="Estilo17"></td>
   <td align="left" class="Estilo6">IMPUESTO </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>


<table width="92%" border="0" cellspacing="0" cellpadding="0">
   
  <tr>
 
   <tr>
       <td></td>
    
	<?php  
 /*   		 
SI ES COLONES 
 */  
 
 $totnosujeto_fac =0;
?>
	<td colspan="15"  align="" >FACTURAS COLONES </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" ><span class="Estilo4"><strong>Factura</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Codigo</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Cliente</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Plazo</strong></font></span></td>
    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exento </strong></font></span></td> 
	<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exonerado </strong></font></span></td>
		 <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.NoSujeto </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Gravado </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Subtotal </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Descuento </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Impuesto </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Imp. Servicio </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Total </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 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 facturas WHERE  fecha  between '$fechainicio' AND '$fechafin'  AND  tipmoneda!= 'USD'  ".$where;
		
	//echo  $consulta;
		if ($resultado = $mysqli->query($consulta)) 

	
	  
 
  		while ($fila = $resultado->fetch_assoc()) {
	
        $fecha         = $fila["fecha"];
		$fecha         = implode("-", array_reverse(explode("-", $fecha)));
		$numfactura    = $fila["numfactura"];
		$numfactura    = substr($numfactura  , 10, 10);
		$codfactura    = $fila["codfactura"];
		$cdgcli        = $fila["cdgcli"];
		$cdgcli        = sprintf("%04d",$cdgcli); 
		$dsccli        = $fila["dsccli"];
		$dsccli        = substr($dsccli, 0, 40);
		$pladia        = $fila["pladia"];
		$totalfactura  = number_format($fila["totalfactura"], 2);
		$subexe        = number_format($fila["subexe"], 2);
		$subgra        = number_format($fila["subgra"], 2);
		$subtot        = number_format($fila["subtot"], 2);
		$impven        = number_format($fila["impven"], 2);
		$destot        = number_format($fila["destot"], 2);
		$otrcar        = number_format($fila["otrcar"], 2);

		
		$totgravado     = number_format($fila["totgravado"], 2);
		$totexento     = number_format($fila["totexento"], 2);
		$totexonerado     = number_format($fila["totexonerado"], 2);
		$totnosujeto     = number_format($fila["totnosujeto"], 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;

	  


	 
	 	 if ($impven >0){   // si el impuesto es mayor a 0
		 
					$consulta2= "SELECT * FROM factulinea WHERE  codfactura =  '$codfactura'   ";
						if ($resultado2 = $mysqli->query($consulta2)) 
				

						while ($fila2 = $resultado2->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        = $fila2["cdgtar"];
						$SubTotal      = $fila2["subtotal"];
						$impuesto      = $fila2["impuesto"];
	
						     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 $numfactura?></font></td>
   <td align="center"><font size=1 ><?php echo $cdgcli?></font></td>
   <td align="left"><font size=1 ><?php echo $dsccli?></font></td>
   <td align="center"><font size=1 ><?php echo $fecha?></font></td>
   <td align="center"><font size=1 ><?php echo $pladia?></font></td>
   <td align="right"><font size=1 ><?php echo $totexento?></font></td>
   <td align="right"><font size=1 ><?php echo $totexonerado ?></font></td>
   <td align="right"><font size=1 ><?php echo $totnosujeto ?></font></td>
   
   <td align="right"><font size=1 ><?php echo $totgravado ?></font></td>
   <td align="right"><font size=1 ><?php echo  $subtot ?></font></td>
   <td align="right"><font size=1 ><?php echo $destot?></font></td>
   <td align="right"><font size=1 ><?php echo $impven ?></font></td>
   <td align="right"><font size=1 ><?php echo $otrcar ?></font></td>
   <td align="right"><font size=1 ><?php echo $totalfactura ?></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(totalfactura) AS total , SUM(subtot) AS subtotal, SUM(subexe) AS exento, SUM(subgra) AS gravado, SUM(totnosujeto) AS totnosujeto, SUM(destot) AS descuento , SUM(impven) AS impuesto, SUM(totexento) AS  totexento, SUM(totexonerado) AS  totexonerado, SUM(totgravado) AS  totgravado , SUM(otrcar) AS  total_otrcar FROM facturas WHERE  fecha  between '$fechainicio' AND '$fechafin'  AND tipmoneda!= 'USD' ".$where );

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

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

				$exento_fac    = $dato['exento'];
				$gravado_fac   = $dato['gravado'];
				$subtotal_fac  = $dato['subtotal'];
				$descuento_fac = $dato['descuento'];
				$impuesto_fac  = $dato['impuesto'];
				$otrcar_fac  = $dato['total_otrcar'];
				$total_fac     = $dato['total'];
				
				$totgravado_fac   = $dato['totgravado'];
				$totexento_fac    = $dato['totexento'];
				$totexonerado_fac    = $dato['totexonerado'];
				$totnosujeto_fac    = $dato['totnosujeto'];
				
				
				
	 } 		
  
  ?>
  
</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>
 </tr>
 <tr>

     <td width="1%"></td>
      <td align="left"><strong><font size=1 >TOTAL FACTURAS COLONES </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="right"><strong><font size=1 ><?php echo number_format($totexento_fac , 2);?></font></strong></td>
      <td align="right"><strong><font size=1 ><?php echo number_format($totexonerado_fac , 2);?></font></strong></td>
	     <td align="right"><strong><font size=1 ><?php echo number_format($totnosujeto_fac, 2); ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($totgravado_fac, 2); ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotal_fac , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($descuento_fac , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($impuesto_fac , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($otrcar_fac  , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($total_fac , 2); ?></font></strong></td>
 </tr>
</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>
 </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">SUBTOTAL </td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I0R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I1R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I2R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I4R  , 2);?></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I0T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I4T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I8T  , 2);?></span></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I13  , 2);?></span></td>

   </tr>
   
    <tr>
	 <td width="1%" class="Estilo17"></td>
   <td align="left" class="Estilo6">IMPUESTO </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>


<table width="92%" border="0" cellspacing="0" cellpadding="0">
   
  <tr>
    <td></td>
    <td colspan="12"  align="center" >&nbsp;</td>
  </tr>
  <tr>
   <tr>
       <td></td>
    
	<td colspan="15"   border="1">NOTAS CREDITO DOLARES </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>
      <td width="1%"></td>

    <td width="20%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Nota Credito</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Codigo</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Cliente</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue">&nbsp;</td>
    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exento </strong></font></span></td> 
	 <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exonerado </strong></font></span></td> 
		 <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.NoSujeto </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Gravado </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Subtotal </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Descuento </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Impuesto </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Imp. Servicio </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Total </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 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 facturas_notas WHERE  fecha  between '$fechainicio' AND '$fechafin'  AND  tipmoneda= 'USD'  ".$where_notas ;
		if ($resultado = $mysqli->query($consulta)) 

  		while ($dato = $resultado->fetch_assoc()) {
	
				$codnota     = $dato["codnota"];
				$numcomp     = $dato["numcomp"];
				$numcomp     = substr($numcomp  , 10, 10);
				$fecha       = $dato["fecha"];
 				$fecha       = implode("-", array_reverse(explode("-", $fecha))); 		
				$cdgcli      = $dato["cdgcli"];
				$cdgcli      = sprintf("%04d",$cdgcli); 
				$dsccli      = $dato["dsccli"];
				$totalnota   = number_format($dato["totalnota"], 2);
				$subexe      = number_format($dato["subexe"], 2);
				$subgra      = number_format($dato["subgra"], 2);
				$subtot      = number_format($dato["subtot"], 2);
				$impven      = number_format($dato["impven"], 2);
				$destot      = number_format($dato["destot"], 2);
				$otrcar      = number_format($dato["otrcar"], 2);
				
				$totgravado     = number_format($dato["totgravado"], 2);
				$totexento     = number_format($dato["totexento"], 2);
				$totexonerado     = number_format($dato["totexonerado"], 2);
				$totnosujeto     = number_format($dato["totnosujeto"], 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;

	  


	 
	 	 if ($impven >0){   // si el impuesto es mayor a 0
		 
					$consulta2= "SELECT * FROM factulinea_notas WHERE  codnota =  '$codnota'   ";
						if ($resultado2 = $mysqli->query($consulta2)) 
				

						while ($fila2 = $resultado2->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        = $fila2["cdgtar"];
						$SubTotal      = $fila2["subtotal"];
						$impuesto      = $fila2["impuesto"];
	
						     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 $numcomp ?></font></td>
   <td align="center"><font size=1 ><?php echo $cdgcli?></font></td>
   <td align="left"><font size=1 ><?php echo $dsccli?></font></td>
   <td align="center"><font size=1 ><?php echo $fecha?></font></td>
   <td align="center"><font size=1 ></font></td>
   <td align="right"><font size=1 ><?php echo $totexento?></font></td>
    <td align="right"><font size=1 ><?php echo $totexonerado ?></font></td>
	<td align="right"><font size=1 ><?php echo $totnosujeto ?></font></td>
	
   <td align="right"><font size=1 ><?php echo $totgravado ?></font></td>
   <td align="right"><font size=1 ><?php echo  $subtot ?></font></td>
   <td align="right"><font size=1 ><?php echo $destot?></font></td>
   <td align="right"><font size=1 ><?php echo $impven ?></font></td>
   <td align="right"><font size=1 ><?php echo $otrcar ?></font></td>
   <td align="right"><font size=1 ><?php echo $totalnota ?></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
	        
		 } 
		 

				$consulta= ("SELECT SUM(totalnota) AS total , SUM(subtot) AS subtotal, SUM(subexe) AS exento, SUM(subgra) AS gravado, SUM(totnosujeto) AS totnosujeto, SUM(destot) AS descuento , SUM(impven) AS impuesto, SUM(totexento) AS  totexento, SUM(totexonerado) AS  totexonerado,SUM(totgravado) AS  totgravado  , SUM(otrcar) AS  total_otrcar FROM facturas_notas WHERE  fecha  between '$fechainicio' AND '$fechafin' AND  tipmoneda= 'USD' ".$where_notas  );
				

		if ($resultado = $mysqli->query($consulta)) 

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

				$exento_not    = $dato["exento"];
				$gravado_not   = $dato["gravado"];
				$subtotal_not  = $dato["subtotal"];
				$descuento_not = $dato["descuento"];
				$impuesto_not  = $dato["impuesto"];
				$otrcar_not  = $dato['total_otrcar'];
				$total_not     = $dato["total"];
				
				$totgravado_not      = $dato["totgravado"];
				$totexento_not   = $dato["totexento"];
				$totexonerado_not   = $dato["totexonerado"];
				$totnosujeto_not   = $dato["totnosujeto"];
  ?>
</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>
 </tr>
 <tr>

     <td width="1%"></td>
      <td align="left"><strong><font size=1 >TOTAL NOTAS CREDITO DOLARES</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="right"><strong><font size=1 ><?php echo  number_format($totexento_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($totexonerado_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($totnosujeto_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($totgravado_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format( $subtotal_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($descuento_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($impuesto_not , 2); ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($otrcar_not  , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($total_not , 2); ?></font></strong></td>
 </tr>
</table>

 



    <?php
	
	
	 } 
	
	
	  ?>
	
	
 <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">SUBTOTAL </td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I0R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I1R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I2R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I4R  , 2);?></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I0T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I4T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I8T  , 2);?></span></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I13  , 2);?></span></td>

   </tr>
   
    <tr>
	 <td width="1%" class="Estilo17"></td>
   <td align="left" class="Estilo6">IMPUESTO </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>


	
<table width="92%" border="0" cellspacing="0" cellpadding="0">
    
    
     
  <tr>
    <td></td>
    <td colspan="12"  align="center" >&nbsp;</td>
  </tr>
  <tr>
   <tr>
       <td></td>
    <td colspan="12"  align="center" >&nbsp;</td>
  </tr>
  <tr>
   <tr>
       <td></td>
    
	<td colspan="15"   border="1">NOTAS CREDITO COLONES</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>
      <td width="1%"></td>

    <td width="20%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Nota Credito</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Codigo</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Cliente</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue">&nbsp;</td>
    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exento </strong></font></span></td> 
	 <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exonerado </strong></font></span></td> 
		 <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.NoSujeto </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Gravado </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Subtotal </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Descuento </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Impuesto </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Imp. Servicio </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Total </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 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 facturas_notas WHERE  fecha  between '$fechainicio' AND '$fechafin'  AND  tipmoneda!= 'USD'  ".$where_notas ;
		if ($resultado = $mysqli->query($consulta)) 

  		while ($dato = $resultado->fetch_assoc()) {
	
				$codnota     = $dato["codnota"];
				$numcomp     = $dato["numcomp"];
				$numcomp     = substr($numcomp  , 10, 10);
				$fecha       = $dato["fecha"];
 				$fecha       = implode("-", array_reverse(explode("-", $fecha))); 		
				$cdgcli      = $dato["cdgcli"];
				$cdgcli      = sprintf("%04d",$cdgcli); 
				$dsccli      = $dato["dsccli"];
				$totalnota   = number_format($dato["totalnota"], 2);
				$subexe      = number_format($dato["subexe"], 2);
				$subgra      = number_format($dato["subgra"], 2);
				$subtot      = number_format($dato["subtot"], 2);
				$impven      = number_format($dato["impven"], 2);
				$destot      = number_format($dato["destot"], 2);
				$otrcar      = number_format($dato["otrcar"], 2);
				
				$totgravado     = number_format($dato["totgravado"], 2);
				$totexento     = number_format($dato["totexento"], 2);
				$totexonerado     = number_format($dato["totexonerado"], 2);
				$totnosujeto     = number_format($dato["totnosujeto"], 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;

	  


	 
	 	 if ($impven >0){   // si el impuesto es mayor a 0
		 
					$consulta2= "SELECT * FROM factulinea_notas WHERE  codnota =  '$codnota'   ";
						if ($resultado2 = $mysqli->query($consulta2)) 
				

						while ($fila2 = $resultado2->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        = $fila2["cdgtar"];
						$SubTotal      = $fila2["subtotal"];
						$impuesto      = $fila2["impuesto"];
	
						     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 $numcomp ?></font></td>
   <td align="center"><font size=1 ><?php echo $cdgcli?></font></td>
   <td align="left"><font size=1 ><?php echo $dsccli?></font></td>
   <td align="center"><font size=1 ><?php echo $fecha?></font></td>
   <td align="center"><font size=1 ></font></td>
   <td align="right"><font size=1 ><?php echo $totexento?></font></td>
    <td align="right"><font size=1 ><?php echo $totexonerado ?></font></td>
	 <td align="right"><font size=1 ><?php echo $totnosujeto ?></font></td>
	
   <td align="right"><font size=1 ><?php echo $totgravado ?></font></td>
   <td align="right"><font size=1 ><?php echo  $subtot ?></font></td>
   <td align="right"><font size=1 ><?php echo $destot?></font></td>
   <td align="right"><font size=1 ><?php echo $impven ?></font></td>
    <td align="right"><font size=1 ><?php echo $otrcar ?></font></td>
   <td align="right"><font size=1 ><?php echo $totalnota ?></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
	        
		 } 
		 

				$consulta= ("SELECT SUM(totalnota) AS total , SUM(subtot) AS subtotal, SUM(subexe) AS exento, SUM(subgra) AS gravado, SUM(totnosujeto) AS totnosujeto, SUM(destot) AS descuento , SUM(impven) AS impuesto, SUM(totexento) AS  totexento, SUM(totexonerado) AS  totexonerado,SUM(totgravado) AS  totgravado  , SUM(otrcar) AS  total_otrcar FROM facturas_notas WHERE  fecha  between '$fechainicio' AND '$fechafin'  AND  tipmoneda!= 'USD' ".$where_notas  );
				

		if ($resultado = $mysqli->query($consulta)) 

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

				$exento_not    = $dato["exento"];
				$gravado_not   = $dato["gravado"];
				$subtotal_not  = $dato["subtotal"];
				$descuento_not = $dato["descuento"];
				$impuesto_not  = $dato["impuesto"];
				$otrcar_not  = $dato['total_otrcar'];
				$total_not     = $dato["total"];
				
				$totgravado_not      = $dato["totgravado"];
				$totexento_not   = $dato["totexento"];
				$totexonerado_not   = $dato["totexonerado"];
				$totnosujeto_not   = $dato["totnosujeto"];
				
  ?>
</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>
 </tr>
 <tr>

     <td width="1%"></td>
      <td align="left"><strong><font size=1 >TOTAL NOTAS CREDITO COLONES </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="right"><strong><font size=1 ><?php echo  number_format($totexento_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($totexonerado_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($totnosujeto_not , 2);?></font></strong></td>
      <td align="right"><strong><font size=1 ><?php echo  number_format($totgravado_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format( $subtotal_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($descuento_not , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($impuesto_not , 2); ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($otrcar_not  , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($total_not , 2); ?></font></strong></td>
 </tr>
</table>

 



    <?php
	
	
	 } 
	
	
	  ?>
	
	
 <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">SUBTOTAL </td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I0R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I1R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I2R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I4R  , 2);?></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I0T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I4T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I8T  , 2);?></span></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I13  , 2);?></span></td>

   </tr>
   
    <tr>
	 <td width="1%" class="Estilo17"></td>
   <td align="left" class="Estilo6">IMPUESTO </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>


	
<table width="92%" border="0" cellspacing="0" cellpadding="0">
    
    
     
  <tr>
    <td></td>
    <td colspan="12"  align="center" >&nbsp;</td>
  </tr>
  <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>
      <td width="1%"></td>
	  

    <td width="20%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Nota Debito</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Codigo</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Cliente</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue">&nbsp;</td>
    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exento </strong></font></span></td> 
	<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Exonerado </strong></font></span></td> 
	<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.NoSujeto </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Sub.Gravado </strong></font></span></td>
	    <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Subtotal </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Descuento </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Impuesto </strong></font></span></td>
		<td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Imp. Servicio </strong></font></span></td>
        <td width="20%" align="right" bgcolor="skyblue"><span class="Estilo4"><strong>Total </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 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 facturas_notas_debito WHERE  fecha  between '$fechainicio' AND '$fechafin'   ".$where_notas ;
		if ($resultado = $mysqli->query($consulta)) 

  		while ($dato = $resultado->fetch_assoc()) {
	
				$codnota     = $dato["codnota"];
				$numcomp     = $dato["numcomp"];
				$numcomp     = substr($numcomp  , 10, 10);
				$fecha       = $dato["fecha"];
 				$fecha       = implode("-", array_reverse(explode("-", $fecha))); 		
				$cdgcli      = $dato["cdgcli"];
				$cdgcli      = sprintf("%04d",$cdgcli); 
				$dsccli      = $dato["dsccli"];
				$totalnota   = number_format($dato["totalnota"], 2);
				$subexe      = number_format($dato["subexe"], 2);
				$subgra      = number_format($dato["subgra"], 2);
				$subtot      = number_format($dato["subtot"], 2);
				$impven      = number_format($dato["impven"], 2);
				$destot      = number_format($dato["destot"], 2);
				$otrcar      = number_format($dato["otrcar"], 2);
				
				$totgravado = number_format($dato["totgravado"], 2);
				$totexento  =  number_format($dato["totexento"], 2);
				$totexonerado  =  number_format($dato["totexonerado"], 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;

	  


	 
	 	 if ($impven >0){   // si el impuesto es mayor a 0
		 
					$consulta2= "SELECT * FROM factulinea_notas_debito WHERE  codnota =  '$codnota'   ";
						if ($resultado2 = $mysqli->query($consulta2)) 
				

						while ($fila2 = $resultado2->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        = $fila2["cdgtar"];
						$SubTotal      = $fila2["subtotal"];
						$impuesto      = $fila2["impuesto"];
	
						     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 $numcomp ?></font></td>
   <td align="center"><font size=1 ><?php echo $cdgcli?></font></td>
   <td align="left"><font size=1 ><?php echo $dsccli?></font></td>
   <td align="center"><font size=1 ><?php echo $fecha?></font></td>
   <td align="center"><font size=1 ></font></td>
   <td align="right"><font size=1 ><?php echo $totexento?></font></td>
   <td align="right"><font size=1 ><?php echo $totexonerado?></font></td>
    <td align="right"><font size=1 ><?php echo $totnosujeto_deb?></font></td>
   <td align="right"><font size=1 ><?php echo $totgravado ?></font></td>
   <td align="right"><font size=1 ><?php echo  $subtot ?></font></td>
   <td align="right"><font size=1 ><?php echo $destot?></font></td>
   <td align="right"><font size=1 ><?php echo $impven ?></font></td>
   <td align="right"><font size=1 ><?php echo $otrcar ?></font></td>
   <td align="right"><font size=1 ><?php echo $totalnota ?></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
	        
		 } 
		 
				
				
				$consulta= ("SELECT SUM(totalnota) AS total , SUM(subtot) AS subtotal, SUM(subexe) AS exento, SUM(subgra) AS gravado, SUM(destot) AS descuento , SUM(impven) AS impuesto, SUM(totexento) AS  totexento, SUM(totexonerado) AS  totexonerado,SUM(totgravado) AS  totgravado , SUM(otrcar) AS  total_otrcar FROM facturas_notas_debito WHERE  fecha  between '$fechainicio' AND '$fechafin'  ".$where_notas  );
		if ($resultado = $mysqli->query($consulta)) 

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

				$exento_deb    = $dato["exento"];
				$gravado_deb   = $dato["gravado"];
				$subtotal_deb  = $dato["subtotal"];
				$descuento_deb = $dato["descuento"];
				$impuesto_deb  = $dato["impuesto"];
				$otrcar_deb  = $dato['total_otrcar'];
				$total_deb     = $dato["total"];
				
				$totgravado_deb  = $dato["totgravado"];
				$totexento_deb  = $dato["totexento"];
				$totexonerado_deb     = $dato["totexonerado"];
  ?>
</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>
 </tr>
 <tr>

     <td width="1%"></td>
      <td align="left"><strong><font size=1 >TOTAL NOTAS DEBITO</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="right"><strong><font size=1 ><?php echo  number_format($totexonerado_deb , 2);?></font></strong></td>
      <td align="right"><strong><font size=1 ><?php echo  number_format($totexonerado_deb , 2);?></font></strong></td>
	     <td align="right"><strong><font size=1 ><?php echo  number_format($totnosujeto_deb  , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($totgravado_deb  , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format( $subtotal_deb , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($descuento_deb , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($impuesto_deb , 2); ?></font></strong></td>
      <td align="right"><strong><font size=1 ><?php echo number_format($otrcar_deb  , 2);?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo  number_format($total_deb , 2); ?></font></strong></td>
 </tr>
</table>




    <?php


	 } 	
	


?>
  <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">SUBTOTAL </td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I0R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I1R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I2R  , 2);?></td>
   <td align="right" class="Estilo17"><?php echo number_format($SUBTOTAL_I4R  , 2);?></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I0T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I4T  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I8T  , 2);?></span></td>
   <td align="right" class="Estilo6">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($SUBTOTAL_I13  , 2);?></span></td>

   </tr>
   
    <tr>
	 <td width="1%" class="Estilo17"></td>
   <td align="left" class="Estilo6">IMPUESTO </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>


	
	<?php
	

    
	  
	  
				$exento = $totexento_fac - $totexento_not +  $totexento_deb ;
				$totexonerado = $totexonerado_fac - $totexonerado_not + $totexonerado_deb;
				//$gravado = $gravado_fac - $gravado_not + $gravado_deb  ;
				$nosujeto = $totnosujeto_fac - $totnosujeto_not + $totnosujeto_deb ;
				$gravado = $totgravado_fac - $totgravado_not + $totgravado_deb ;
				$subtotal =$subtotal_fac - $subtotal_not + $subtotal_deb ;
				$descuento  = $descuento_fac - $descuento_not + $descuento_deb ;
				$impuesto =  $impuesto_fac - $impuesto_not +  $impuesto_deb ;
				$impuesto_servicio =  $otrcar_fac - $otrcar_not +  $otrcar_deb ;
				$total = $total_fac - $total_not +  $total_deb ;
  ?>
  
  
  
  <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>
 </tr>
 <tr>

   <td width="1%" class="Estilo17"></td>
   <td align="left" class="Estilo6"><span class="Estilo17">TOTALES</span></td>
  <td align="center" class="Estilo17">&nbsp;</td>
   <td align="left" class="Estilo17">&nbsp;</td>
   <td align="center" class="Estilo17">&nbsp;</td>
   <td align="center" class="Estilo17">&nbsp;</td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($exento  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($totexonerado  , 2);?></span></td>
     <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($nosujeto  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($gravado  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($subtotal , 2); ?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($descuento  , 2);?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($impuesto , 2); ?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($impuesto_servicio , 2); ?></span></td>
   <td align="right" class="Estilo6"><span class="Estilo17"><?php echo number_format($total  , 2); ?></span></td>
 </tr>
</table>



</body>
</html>

 <?php