<?php

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Reporte_comprobantes_FACTURAS.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"];
	   
	 $cedcli    = $_GET["cedcli"];
	 $fecini    = $_GET["fechainicio"];
	 $fecfin    = $_GET["fechafin"];
	 $cdgtipven = $_GET["combotipoventa"];
	 $cdgcaj    = $_GET["cdgcaj"];
	 $cdgtipocxp    = $_GET["cdgtipocxp"];
	 $combotipomoneda    = $_GET["combotipomoneda"];
	 
	 
	 
	 
	$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;
	 	 /////////////////        where para facturas ********************
	 

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

$where="1=1";
//if ($cedcli <> "") { $where.=" AND numcedemi like '%".$cedcli."%'"; }
if ($cedcli <> "") { $where.=" AND x.numcedemi ='".$cedcli."'"; }

if ($cdgtipocxp <> "") { $where.=" AND x.cdgcxp ='".$cdgtipocxp."'"; }



if (($fechainicio<>"") and ($fechafin<>"")) {

 		//	$dias=1;
//
//		$inicio= "-".$dias." day" ;
//			$fechainicio = strtotime ( $inicio , strtotime ( $fechainicio ) ) ;
//		$fechainicio = date ( 'Y-m-d' , $fechainicio );
//
//			$fin= "+".$dias." day" ;
//	 	$fechafin = strtotime ( $fin , strtotime ($fechafin ) ) ;
//			$fechafin = date ( 'Y-m-d' , $fechafin );
			
	 $where.=" AND x.feccorcomp between '".$fechainicio."' AND '".$fechafin."'";
} else {
	if ($fechainicio<>"") {
	 	$where.=" AND x.feccorcomp>='".$fechainicio."'";
	} else {
		if ($fechafin<>"") {
		$where.=" AND x.feccorcomp<='".$fechafin."'";
		}
	}
}

 if ($cdgtipocxp=="") {
	 
	 $nomcomusu="TODOS LOS COMPROBANTES";
	 
	     } else {


	   $query_codcaj="SELECT * FROM tipo_cxp  WHERE cdgcxp=$cdgtipocxp ";
       $resultado = $mysqli->query( $query_codcaj);
       $row = $resultado->fetch_array();
        
		$nomcomusu    = $row["dsccxp"];
     }
	 
	 
			
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Reporte de Comprobantes Aceptados</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>

<?php      		 
if ($combotipomoneda == "USD") { 
$where.=" AND x.tipmoneda='USD'"; 
?>
<table width="92%" border="0" cellspacing="0" cellpadding="0">
    
    <tr>
      <td><div align="center"></div></td>
      <td colspan="14"  ><div align="center"><font size=5 ><?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 de Comprobantes FACTURAS DOLARES</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>
	
  <td></td>
    
	<td colspan="16"   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>Numero Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Fecha  Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Estado  Mensaje</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>TIPO</strong></font></span></td>
    <td width="20%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Proveedor</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Estado Hacienda</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Exento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Gravado</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Descuento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto</strong></font></span></td>			
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Total Comprobante</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
		

	// $consulta = "SELECT * FROM mensaje_receptor WHERE ".$where." ORDER BY tipcom , feccomp ASC";
	  $consulta = "SELECT x.codmen, x.cdgclavemen, x.numcompmen, x.fecmen, x.cdgclavecomp, x.numcomp,
 x.feccomp, x.feccorcomp,  x.cdgmen, x.detmen, x.totdes, x.subtotgra, x.subtotexe,
 x.subtotal, x.monimp, x.imptr0, x.imptr1, x.imptr2, x.imptr4, x.impts0, x.impts4,
 x.impts8, x.impg13, x.subtr0, x.subtr1, x.subtr2, x.subtr4, x.subts0, x.subts4,
 x.subts8, x.subg13, x.totcomp, x.numcedrec, x.cedtiprec, x.dscnomemi, x.numcedemi,
 x.cedtipemi, x.estadoComprobanteIntegracion,x.tipcom, x.cdgcxp ,z.dsccxp
 FROM mensaje_receptor x ,tipo_cxp z 
WHERE  x.cdgcxp=z.cdgcxp AND  x.tipcom = 'FAC' AND ".$where."  ORDER BY x.cdgcxp,   x.fecmen ASC";


		if ($resultado3 = $mysqli->query($consulta)) 		
		if($dato = $resultado3->fetch_assoc()){ 
      	$cdgcxp_actual = $dato['cdgcxp'];
		

	   } 
	   

	   
		$subtotgracom = 0;
		$subtotexecom = 0;
		$subtotalcom  = 0;
		$subtotaldescom  = 0;	
		$subtotalimpcom  = 0;	
		$subtotalgrancom  = 0;	

		/******REDUCIDA************/
		$subtr0com = 0;
		$imptr0com = 0;
		$subtr1com = 0;
		$imptr1com = 0;
		$subtr2com = 0;
		$imptr2com = 0;
		$subtr4com = 0;
		$imptr4com = 0;

		/******TRANSITORIA************/	   
		$subts0com = 0;
		$impts0com = 0;
		$subts4com = 0;
		$impts4com = 0;
		$subts8com = 0;
		$impts8com = 0;

		/******GENERAL************/
		$subg13com = 0;
		$impg13com = 0;
	   
$contador=0;  
if ($resultado = $mysqli->query($consulta)) 

 
    while ($fila = $resultado->fetch_assoc()) {
		$numcompmen = $fila["numcompmen"];
		$numcompmen    = "MEN-".$numcompmen ;
		$fecmen     = $fila["fecmen"];
		$cdgclavecomp     = $fila["cdgclavecomp"];
		$feccomp    = $fila["feccomp"];
        $dscnomemi   = $fila["dscnomemi"];
		$tipcom     = $fila["tipcom"];
        $numcomp    = $fila["numcomp"];
		$numcomp    = "DOC-".$numcomp ;
	    $detmen     = $fila["detmen"];
		$subtotgra  = $fila["subtotgra"];
		$subtotexe  = $fila["subtotexe"];
        $subtotal   = $fila["subtotal"];
		$cdgcxp   = $fila["cdgcxp"];
		$dsccxp   = $fila["dsccxp"];
		
	

		$imptr0     = $fila["imptr0"];
		$imptr1     = $fila["imptr1"];
		$imptr2     = $fila["imptr2"];
		$imptr4     = $fila["imptr4"];	
		$impts0     = $fila["impts0"];
		$impts4     = $fila["impts4"];
		$impts8     = $fila["impts8"];
		$impg13     = $fila["impg13"];
		
		$subtr0     = $fila["subtr0"];
		$subtr1     = $fila["subtr1"];
		$subtr2     = $fila["subtr2"];
		$subtr4     = $fila["subtr4"];	
		$subts0     = $fila["subts0"];
		$subts4     = $fila["subts4"];
		$subts8     = $fila["subts8"];
		$subg13     = $fila["subg13"];
		
		
        $totdes     = $fila["totdes"];	
        $monimp     = $fila["monimp"];
        
		if ($monimp ==" ")  { $monimp = 0 ; 	}
		
		$totcomp    = $fila["totcomp"];
		$numcedemi  = $fila["numcedemi"];
		$estado     = $fila["estadoComprobanteIntegracion"];
		$codmen     = $fila["codmen"];
	    $fecha     = substr($fecmen,0,10);
        $fecmen   = implode("-", array_reverse(explode("-", $fecha))); 
		$numcompmen1   = $fila["numcompmen"];
		$fecha     = substr($feccomp,0,10);
        $feccomp   = implode("-", array_reverse(explode("-", $fecha))); 
		
	if ($cdgcxp_actual==$cdgcxp) {   // si el codigo de  es distinto al siguiente
	
		$subtotgra  = $fila["subtotgra"];
		$subtotexe  = $fila["subtotexe"];
        $subtotal   = $fila["subtotal"];
        $totdes     = $fila["totdes"];	
        $monimp     = $fila["monimp"];
		$totcomp    = $fila["totcomp"];
				
		$subtotexecom = $subtotexecom + $subtotexe;		
		$subtotgracom = $subtotgracom + $subtotgra;
        $subtotalcom  = $subtotalcom + $subtotal ;
		$subtotaldescom  = $subtotaldescom + $totdes ;	
		$subtotalimpcom  = $subtotalimpcom + $monimp;	
		$subtotalgrancom  = $subtotalgrancom  + $totcomp;	
		
		/******IMPUESTOS************/
        $imptr0     = $fila["imptr0"];
		$imptr1     = $fila["imptr1"];
		$imptr2     = $fila["imptr2"];
		$imptr4     = $fila["imptr4"];	
		$impts0     = $fila["impts0"];
		$impts4     = $fila["impts4"];
		$impts8     = $fila["impts8"];
		$impg13     = $fila["impg13"];
		/******SUBTOTALES************/
		$subtr0     = $fila["subtr0"];
		$subtr1     = $fila["subtr1"];
		$subtr2     = $fila["subtr2"];
		$subtr4     = $fila["subtr4"];	
		$subts0     = $fila["subts0"];
		$subts4     = $fila["subts4"];
		$subts8     = $fila["subts8"];
		$subg13     = $fila["subg13"];
		/******REDUCIDA************/
		$subtr0com = $subtr0com + $subtr0 ;
		$imptr0com = $imptr0com + $imptr0;
		$subtr1com = $subtr1com + $subtr1;
		$imptr1com = $imptr1com + $imptr1;
		$subtr2com = $subtr2com + $subtr2;
		$imptr2com = $imptr2com + $imptr2;
		$subtr4com = $subtr4com + $subtr4;
		$imptr4com = $imptr4com + $imptr4;
		/******TRANSITORIA************/	   
		$subts0com = $subts0com + $subts0;
		$impts0com = $impts0com + $impts0;
		$subts4com = $subts4com + $subts4;
		$impts4com = $impts4com + $impts4 ;
		$subts8com = $subts8com  + $subts8;
		$impts8com = $impts8com + $impts8 ;
		/******GENERAL************/
		$subg13com = $subg13com + $subg13;
		$impg13com = $impg13com + $impg13;
	}

		$consult = "SELECT * FROM hac_estados WHERE cdgesthac = '$estado' ";
		$result = $mysqli->query($consult);
		$fila2 = $result->fetch_array();

         $dscesthac = $fila2["dscesthac"];
		 
	

          if ($contador==0){ 
?>  
 
      <tr>
	     <td></td>
        <td> <strong> <font size=2 ><?php echo $cdgcxp." - ".$dsccxp. " FACTURAS" ?></font></strong></td>
        <td>  <font size=2 ></font></td>
   	    <td>  <font size=1 align="right"></font></td>
   	    <td>  <font size=1 align="left"></font></td>
		<td align="center">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
		 <td  align="right">  <font size=1 ></font></td>
		  <td  align="right">  <font size=1 ></font></td>


      </tr>


  
  <?php
  
       
		 } 
		 

	if ($cdgcxp <>  $cdgcxp_actual  ){ 
				
			 $cdgcxp_actual = $fila['cdgcxp'];
				 
?> 
 <tr>
 </tr>
 <tr>
   <td></td>
   <td align="left"><strong><font size=1 >Subtotal Comprobantes</ </font></strong></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotexecom ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotgracom  ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalcom,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotaldescom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php  echo number_format($subtotalimpcom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalgrancom,2) ?></font></strong></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <!-- /******REDUCIDA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr4com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr4com,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td>    
   <!-- /******TRANSITORIA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts8com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts8com ,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td> 
    <!-- /******GENERAL************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subg13com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impg13com ,2) ?></font></strong></td>  
   
 </tr>
 

 
  <tr>
  <tr>
   <td></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 colspan="16"   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>Numero Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Fecha  Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Estado  Mensaje</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>TIPO</strong></font></span></td>
    <td width="20%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Proveedor</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Estado Hacienda</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Exento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Gravado</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Descuento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto</strong></font></span></td>			
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Total Comprobante</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>
        <tr>
	     <td></td>
        <td> <strong> <font size=2 ><?php echo $cdgcxp." - ".$dsccxp. " FACTURAS" ?></font></strong></td>

        <td>  <font size=2 ></font></td>
   	    <td>  <font size=1 align="right"></font></td>
   	    <td>  <font size=1 align="left"></font></td>
		<td align="center">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
		 <td  align="right">  <font size=1 ></font></td>
		  <td  align="right">  <font size=1 ></font></td>


      </tr>

  
 
<?php

		$subtotgracom = 0;
		$subtotexecom = 0;
        $subtotalcom  = 0;
		$subtotaldescom  = 0;	
		$subtotalimpcom  = 0;	
		$subtotalgrancom  = 0;
		
		/******REDUCIDA************/
		$subtr0com = 0;
		$imptr0com = 0;
		$subtr1com = 0;
		$imptr1com = 0;
		$subtr2com = 0;
		$imptr2com = 0;
		$subtr4com = 0;
		$imptr4com = 0;

		/******TRANSITORIA************/	   
		$subts0com = 0;
		$impts0com = 0;
		$subts4com = 0;
		$impts4com = 0;
		$subts8com = 0;
		$impts8com = 0;

		/******GENERAL************/
		$subg13com = 0;
		$impg13com = 0;
		
		$subtotgra  = $fila["subtotgra"];
		$subtotexe  = $fila["subtotexe"];
        $subtotal   = $fila["subtotal"];
        $totdes     = $fila["totdes"];	
        $monimp     = $fila["monimp"];
		$totcomp    = $fila["totcomp"];
		
		

		
		$subtotgracom = $subtotgracom + $subtotgra;
		$subtotexecom = $subtotexecom + $subtotexe;				
        $subtotalcom  = $subtotalcom + $subtotal ;
		$subtotaldescom  = $subtotaldescom + $totdes ;	
		$subtotalimpcom  = $subtotalimpcom + $monimp;	
		$subtotalgrancom  = $subtotalgrancom  + $totcomp;
		
				/******IMPUESTOS************/
        $imptr0     = $fila["imptr0"];
		$imptr1     = $fila["imptr1"];
		$imptr2     = $fila["imptr2"];
		$imptr4     = $fila["imptr4"];	
		$impts0     = $fila["impts0"];
		$impts4     = $fila["impts4"];
		$impts8     = $fila["impts8"];
		$impg13     = $fila["impg13"];
		/******SUBTOTALES************/
		$subtr0     = $fila["subtr0"];
		$subtr1     = $fila["subtr1"];
		$subtr2     = $fila["subtr2"];
		$subtr4     = $fila["subtr4"];	
		$subts0     = $fila["subts0"];
		$subts4     = $fila["subts4"];
		$subts8     = $fila["subts8"];
		$subg13     = $fila["subg13"];
		/******REDUCIDA************/
		$subtr0com = $subtr0com + $subtr0 ;
		$imptr0com = $imptr0com + $imptr0;
		$subtr1com = $subtr1com + $subtr1;
		$imptr1com = $imptr1com + $imptr1;
		$subtr2com = $subtr2com + $subtr2;
		$imptr2com = $imptr2com + $imptr2;
		$subtr4com = $subtr4com + $subtr4;
		$imptr4com = $imptr4com + $imptr4;
		/******TRANSITORIA************/	   
		$subts0com = $subts0com + $subts0;
		$impts0com = $impts0com + $impts0;
		$subts4com = $subts4com + $subts4;
		$impts4com = $impts4com + $impts4 ;
		$subts8com = $subts8com  + $subts8;
		$impts8com = $impts8com + $impts8 ;
		/******GENERAL************/
		$subg13com = $subg13com + $subg13;
		$impg13com = $impg13com + $impg13;
		
		
		
} // fin 	if ($cdgcxp <>  $cdgcxp_actual  ){ 

?> 
<tr>
   <td></td>
   <td align="left"><font size=1 ><?php echo $numcompmen ?></font></td>
   <td align="center"><font size=1 ><?php echo  $fecmen ?></font></td>
   <td align="center"><font size=1 ><?php echo  $detmen ?></font></td>
   <td align="center"><font size=1 ></font></td>   
   <td align="center"><font size=1 ><?php echo $tipcom ?></font></td>
   <td align="center"><font size=1 ><?php echo $numcomp ?></font></td>
   <td align="center"><font size=1 ><?php echo $feccomp  ?></font></td>
   <td align="left"><font size=1 >  <?php echo  $dscnomemi?></font></td>
   <td align="center"><font size=1 ><?php echo  $dscesthac ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtotexe,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtotgra,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtotal,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($totdes,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($monimp,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($totcomp,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($subtr0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtr1,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr1,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtr2,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr2,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtr4,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr4,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($subts0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impts0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subts4,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impts4,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subts8,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impts8,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($subg13,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impg13,2) ?></font></td>
 </tr>
  <?PHP   
	$contador++;
	} //fin while


?>
   </tr>
 <tr>
   <td></td>
   <td align="left"><strong><font size=1 >Subtotal Comprobantes </font></strong></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotexecom ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotgracom  ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalcom,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotaldescom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php  echo number_format($subtotalimpcom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalgrancom,2) ?></font></strong></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <!-- /******REDUCIDA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr4com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr4com,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td>    
   <!-- /******TRANSITORIA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts8com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts8com ,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td> 
    <!-- /******GENERAL************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subg13com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impg13com ,2) ?></font></strong></td>  

 </tr>

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

</table>




<?php 



	  $consulta2 = "SELECT  SUM(x.totdes) AS totdes, SUM(x.subtotgra) AS subtotgra,
 SUM(x.subtotexe) AS subtotexe, SUM(x.subtotal) AS subtotal, SUM(x.monimp) AS monimp, SUM(x.imptr0) AS imptr0,
 SUM(x.imptr1) AS imptr1, SUM(x.imptr2) AS imptr2, 
 SUM(x.imptr4) AS imptr4, SUM(x.impts4) AS impts4, SUM(x.impts0) AS impts0,
 SUM(x.impts8) AS impts8, SUM(x.impg13) AS impg13, SUM(x.subtr0) AS subtr0, SUM(x.subtr1) AS subtr1,
 SUM(x.subtr2) AS subtr2, SUM(x.subtr4) AS subtr4, SUM(x.subts0) AS subts0, SUM(x.subts4) AS subts4,
 SUM(x.subts8) AS subts8, SUM(x.subg13) AS subg13, SUM(x.totcomp) AS totcomp
 FROM mensaje_receptor x ,tipo_cxp z 
WHERE  x.cdgcxp=z.cdgcxp AND  x.tipcom = 'FAC'   AND ".$where."  ORDER BY x.fecmen,x.cdgcxp ASC";

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

  	 while ($dato = $resultado2->fetch_assoc()) {
  						
		$subtotgraT  = $dato["subtotgra"];
		$subtotexeT  = $dato["subtotexe"];
        $subtotalT   = $dato["subtotal"];
        $totdesT     = $dato["totdes"];	
        $monimpT     = $dato["monimp"];
		$totcompT    = $dato["totcomp"];
		

		
				/******IMPUESTOS************/
        $imptr0T     = $dato["imptr0"];
		$imptr1T     = $dato["imptr1"];
		$imptr2T     = $dato["imptr2"];
		$imptr4T     = $dato["imptr4"];	
		$impts0T     = $dato["impts0"];
		$impts4T     = $dato["impts4"];
		$impts8T     = $dato["impts8"];
		$impg13T     = $dato["impg13"];
		/******SUBTOTALES************/
		$subtr0T     = $dato["subtr0"];
		$subtr1T     = $dato["subtr1"];
		$subtr2T     = $dato["subtr2"];
		$subtr4T     = $dato["subtr4"];	
		$subts0T     = $dato["subts0"];
		$subts4T     = $dato["subts4"];
		$subts8T     = $dato["subts8"];
		$subg13T     = $dato["subg13"];
					
	
	} 
	?>
<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"><strong><font size=1 >TOTAL FACTURACION</font></strong></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotexeT ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotgraT  ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalT,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($totdesT ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php  echo number_format($monimpT ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($totcompT,2) ?></font></strong></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <!-- /******REDUCIDA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr0T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr0T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr1T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr1T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr2T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr2T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr4T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr4T,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td>    
   <!-- /******TRANSITORIA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subts0T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts0T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts4T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts4T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts8T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts8T ,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td> 
    <!-- /******GENERAL************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subg13T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impg13T ,2) ?></font></strong></td>  

 </tr>
</table>

	
<?php 	
 } // fin con dolares
     		 
else { 
//`tipmoneda` != 'USD'

$where.=" AND x.tipmoneda!= 'USD'";   // todos los distintos a USD

?>
<table width="92%" border="0" cellspacing="0" cellpadding="0">
    
    <tr>
      <td><div align="center"></div></td>
      <td colspan="14"  ><div align="center"><font size=5 ><?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 de Comprobantes FACTURAS COLONES</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>

  <td></td>
    
	<td colspan="16"   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>Numero Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Fecha  Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Estado  Mensaje</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>TIPO</strong></font></span></td>
    <td width="20%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Proveedor</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Estado Hacienda</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Exento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Gravado</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Descuento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto</strong></font></span></td>			
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Total Comprobante</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
		

	// $consulta = "SELECT * FROM mensaje_receptor WHERE ".$where." ORDER BY tipcom , feccomp ASC";
	  $consulta = "SELECT x.codmen, x.cdgclavemen, x.numcompmen, x.fecmen, x.cdgclavecomp, x.numcomp,
 x.feccomp, x.feccorcomp,  x.cdgmen, x.detmen, x.totdes, x.subtotgra, x.subtotexe,
 x.subtotal, x.monimp, x.imptr0, x.imptr1, x.imptr2, x.imptr4, x.impts0, x.impts4,
 x.impts8, x.impg13, x.subtr0, x.subtr1, x.subtr2, x.subtr4, x.subts0, x.subts4,
 x.subts8, x.subg13, x.totcomp, x.numcedrec, x.cedtiprec, x.dscnomemi, x.numcedemi,
 x.cedtipemi, x.estadoComprobanteIntegracion,x.tipcom, x.cdgcxp ,z.dsccxp
 FROM mensaje_receptor x ,tipo_cxp z 
WHERE  x.cdgcxp=z.cdgcxp AND  x.tipcom = 'FAC' AND ".$where."  ORDER BY x.cdgcxp,   x.fecmen ASC";


		if ($resultado3 = $mysqli->query($consulta)) 		
		if($dato = $resultado3->fetch_assoc()){ 
      	$cdgcxp_actual = $dato['cdgcxp'];
		

	   } 
	   

	   
		$subtotgracom = 0;
		$subtotexecom = 0;
		$subtotalcom  = 0;
		$subtotaldescom  = 0;	
		$subtotalimpcom  = 0;	
		$subtotalgrancom  = 0;	

		/******REDUCIDA************/
		$subtr0com = 0;
		$imptr0com = 0;
		$subtr1com = 0;
		$imptr1com = 0;
		$subtr2com = 0;
		$imptr2com = 0;
		$subtr4com = 0;
		$imptr4com = 0;

		/******TRANSITORIA************/	   
		$subts0com = 0;
		$impts0com = 0;
		$subts4com = 0;
		$impts4com = 0;
		$subts8com = 0;
		$impts8com = 0;

		/******GENERAL************/
		$subg13com = 0;
		$impg13com = 0;
	   
$contador=0;  
if ($resultado = $mysqli->query($consulta)) 

 
    while ($fila = $resultado->fetch_assoc()) {
		$numcompmen = $fila["numcompmen"];
		$numcompmen    = "MEN-".$numcompmen ;
		$fecmen     = $fila["fecmen"];
		$cdgclavecomp     = $fila["cdgclavecomp"];
		$feccomp    = $fila["feccomp"];
        $dscnomemi   = $fila["dscnomemi"];
		$tipcom     = $fila["tipcom"];
        $numcomp    = $fila["numcomp"];
		$numcomp    = "DOC-".$numcomp ;
	    $detmen     = $fila["detmen"];
		$subtotgra  = $fila["subtotgra"];
		$subtotexe  = $fila["subtotexe"];
        $subtotal   = $fila["subtotal"];
		$cdgcxp   = $fila["cdgcxp"];
		$dsccxp   = $fila["dsccxp"];
		
	

		$imptr0     = $fila["imptr0"];
		$imptr1     = $fila["imptr1"];
		$imptr2     = $fila["imptr2"];
		$imptr4     = $fila["imptr4"];	
		$impts0     = $fila["impts0"];
		$impts4     = $fila["impts4"];
		$impts8     = $fila["impts8"];
		$impg13     = $fila["impg13"];
		
		$subtr0     = $fila["subtr0"];
		$subtr1     = $fila["subtr1"];
		$subtr2     = $fila["subtr2"];
		$subtr4     = $fila["subtr4"];	
		$subts0     = $fila["subts0"];
		$subts4     = $fila["subts4"];
		$subts8     = $fila["subts8"];
		$subg13     = $fila["subg13"];
		
		
        $totdes     = $fila["totdes"];	
        $monimp     = $fila["monimp"];
        
		if ($monimp ==" ")  { $monimp = 0 ; 	}
		
		$totcomp    = $fila["totcomp"];
		$numcedemi  = $fila["numcedemi"];
		$estado     = $fila["estadoComprobanteIntegracion"];
		$codmen     = $fila["codmen"];
	    $fecha     = substr($fecmen,0,10);
        $fecmen   = implode("-", array_reverse(explode("-", $fecha))); 
		$numcompmen1   = $fila["numcompmen"];
		$fecha     = substr($feccomp,0,10);
        $feccomp   = implode("-", array_reverse(explode("-", $fecha))); 
		
	if ($cdgcxp_actual==$cdgcxp) {   // si el codigo de  es distinto al siguiente
	
		$subtotgra  = $fila["subtotgra"];
		$subtotexe  = $fila["subtotexe"];
        $subtotal   = $fila["subtotal"];
        $totdes     = $fila["totdes"];	
        $monimp     = $fila["monimp"];
		$totcomp    = $fila["totcomp"];
				
		$subtotexecom = $subtotexecom + $subtotexe;		
		$subtotgracom = $subtotgracom + $subtotgra;
        $subtotalcom  = $subtotalcom + $subtotal ;
		$subtotaldescom  = $subtotaldescom + $totdes ;	
		$subtotalimpcom  = $subtotalimpcom + $monimp;	
		$subtotalgrancom  = $subtotalgrancom  + $totcomp;	
		
		/******IMPUESTOS************/
        $imptr0     = $fila["imptr0"];
		$imptr1     = $fila["imptr1"];
		$imptr2     = $fila["imptr2"];
		$imptr4     = $fila["imptr4"];	
		$impts0     = $fila["impts0"];
		$impts4     = $fila["impts4"];
		$impts8     = $fila["impts8"];
		$impg13     = $fila["impg13"];
		/******SUBTOTALES************/
		$subtr0     = $fila["subtr0"];
		$subtr1     = $fila["subtr1"];
		$subtr2     = $fila["subtr2"];
		$subtr4     = $fila["subtr4"];	
		$subts0     = $fila["subts0"];
		$subts4     = $fila["subts4"];
		$subts8     = $fila["subts8"];
		$subg13     = $fila["subg13"];
		/******REDUCIDA************/
		$subtr0com = $subtr0com + $subtr0 ;
		$imptr0com = $imptr0com + $imptr0;
		$subtr1com = $subtr1com + $subtr1;
		$imptr1com = $imptr1com + $imptr1;
		$subtr2com = $subtr2com + $subtr2;
		$imptr2com = $imptr2com + $imptr2;
		$subtr4com = $subtr4com + $subtr4;
		$imptr4com = $imptr4com + $imptr4;
		/******TRANSITORIA************/	   
		$subts0com = $subts0com + $subts0;
		$impts0com = $impts0com + $impts0;
		$subts4com = $subts4com + $subts4;
		$impts4com = $impts4com + $impts4 ;
		$subts8com = $subts8com  + $subts8;
		$impts8com = $impts8com + $impts8 ;
		/******GENERAL************/
		$subg13com = $subg13com + $subg13;
		$impg13com = $impg13com + $impg13;
	}

		$consult = "SELECT * FROM hac_estados WHERE cdgesthac = '$estado' ";
		$result = $mysqli->query($consult);
		$fila2 = $result->fetch_array();

         $dscesthac = $fila2["dscesthac"];
		 
	

          if ($contador==0){ 
?>  
 
      <tr>
	     <td></td>
        <td> <strong> <font size=2 ><?php echo $cdgcxp." - ".$dsccxp. " FACTURAS" ?></font></strong></td>
        <td>  <font size=2 ></font></td>
   	    <td>  <font size=1 align="right"></font></td>
   	    <td>  <font size=1 align="left"></font></td>
		<td align="center">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
		 <td  align="right">  <font size=1 ></font></td>
		  <td  align="right">  <font size=1 ></font></td>


      </tr>


  
  <?php
  
       
		 } 
		 

	if ($cdgcxp <>  $cdgcxp_actual  ){ 
				
			 $cdgcxp_actual = $fila['cdgcxp'];
				 
?> 
 <tr>
 </tr>
 <tr>
   <td></td>
   <td align="left"><strong><font size=1 >Subtotal Comprobantes</ </font></strong></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotexecom ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotgracom  ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalcom,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotaldescom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php  echo number_format($subtotalimpcom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalgrancom,2) ?></font></strong></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <!-- /******REDUCIDA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr4com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr4com,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td>    
   <!-- /******TRANSITORIA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts8com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts8com ,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td> 
    <!-- /******GENERAL************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subg13com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impg13com ,2) ?></font></strong></td>  
   
 </tr>
 

 
  <tr>
  <tr>
   <td></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 colspan="16"   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>Numero Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Fecha  Mensaje</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Estado  Mensaje</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>TIPO</strong></font></span></td>
    <td width="20%"  align="center"bgcolor="skyblue" ><span class="Estilo4"><strong>Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Fecha Documento</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Proveedor</strong></font></span></td>
    <td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Estado Hacienda</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Exento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal Gravado</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Subtotal</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Descuento</strong></font></span></td>
	<td width="20%" align="center" bgcolor="skyblue" ><span class="Estilo4"><strong>Impuesto</strong></font></span></td>			
	<td width="20%" align="center" bgcolor="skyblue"><span class="Estilo4"><strong>Total Comprobante</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>
        <tr>
	     <td></td>
        <td> <strong> <font size=2 ><?php echo $cdgcxp." - ".$dsccxp. " FACTURAS" ?></font></strong></td>

        <td>  <font size=2 ></font></td>
   	    <td>  <font size=1 align="right"></font></td>
   	    <td>  <font size=1 align="left"></font></td>
		<td align="center">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
        <td  align="right">  <font size=1 ></font></td>
		 <td  align="right">  <font size=1 ></font></td>
		  <td  align="right">  <font size=1 ></font></td>


      </tr>

  
 
<?php

		$subtotgracom = 0;
		$subtotexecom = 0;
        $subtotalcom  = 0;
		$subtotaldescom  = 0;	
		$subtotalimpcom  = 0;	
		$subtotalgrancom  = 0;
		
		/******REDUCIDA************/
		$subtr0com = 0;
		$imptr0com = 0;
		$subtr1com = 0;
		$imptr1com = 0;
		$subtr2com = 0;
		$imptr2com = 0;
		$subtr4com = 0;
		$imptr4com = 0;

		/******TRANSITORIA************/	   
		$subts0com = 0;
		$impts0com = 0;
		$subts4com = 0;
		$impts4com = 0;
		$subts8com = 0;
		$impts8com = 0;

		/******GENERAL************/
		$subg13com = 0;
		$impg13com = 0;
		
		$subtotgra  = $fila["subtotgra"];
		$subtotexe  = $fila["subtotexe"];
        $subtotal   = $fila["subtotal"];
        $totdes     = $fila["totdes"];	
        $monimp     = $fila["monimp"];
		$totcomp    = $fila["totcomp"];
		
		

		
		$subtotgracom = $subtotgracom + $subtotgra;
		$subtotexecom = $subtotexecom + $subtotexe;				
        $subtotalcom  = $subtotalcom + $subtotal ;
		$subtotaldescom  = $subtotaldescom + $totdes ;	
		$subtotalimpcom  = $subtotalimpcom + $monimp;	
		$subtotalgrancom  = $subtotalgrancom  + $totcomp;
		
				/******IMPUESTOS************/
        $imptr0     = $fila["imptr0"];
		$imptr1     = $fila["imptr1"];
		$imptr2     = $fila["imptr2"];
		$imptr4     = $fila["imptr4"];	
		$impts0     = $fila["impts0"];
		$impts4     = $fila["impts4"];
		$impts8     = $fila["impts8"];
		$impg13     = $fila["impg13"];
		/******SUBTOTALES************/
		$subtr0     = $fila["subtr0"];
		$subtr1     = $fila["subtr1"];
		$subtr2     = $fila["subtr2"];
		$subtr4     = $fila["subtr4"];	
		$subts0     = $fila["subts0"];
		$subts4     = $fila["subts4"];
		$subts8     = $fila["subts8"];
		$subg13     = $fila["subg13"];
		/******REDUCIDA************/
		$subtr0com = $subtr0com + $subtr0 ;
		$imptr0com = $imptr0com + $imptr0;
		$subtr1com = $subtr1com + $subtr1;
		$imptr1com = $imptr1com + $imptr1;
		$subtr2com = $subtr2com + $subtr2;
		$imptr2com = $imptr2com + $imptr2;
		$subtr4com = $subtr4com + $subtr4;
		$imptr4com = $imptr4com + $imptr4;
		/******TRANSITORIA************/	   
		$subts0com = $subts0com + $subts0;
		$impts0com = $impts0com + $impts0;
		$subts4com = $subts4com + $subts4;
		$impts4com = $impts4com + $impts4 ;
		$subts8com = $subts8com  + $subts8;
		$impts8com = $impts8com + $impts8 ;
		/******GENERAL************/
		$subg13com = $subg13com + $subg13;
		$impg13com = $impg13com + $impg13;
		
		
		
} // fin 	if ($cdgcxp <>  $cdgcxp_actual  ){ 

?> 
<tr>
   <td></td>
   <td align="left"><font size=1 ><?php echo $numcompmen ?></font></td>
   <td align="center"><font size=1 ><?php echo  $fecmen ?></font></td>
   <td align="center"><font size=1 ><?php echo  $detmen ?></font></td>
   <td align="center"><font size=1 ></font></td>   
   <td align="center"><font size=1 ><?php echo $tipcom ?></font></td>
   <td align="center"><font size=1 ><?php echo $numcomp ?></font></td>
   <td align="center"><font size=1 ><?php echo $feccomp  ?></font></td>
   <td align="left"><font size=1 >  <?php echo  $dscnomemi?></font></td>
   <td align="center"><font size=1 ><?php echo  $dscesthac ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtotexe,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtotgra,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtotal,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($totdes,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($monimp,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($totcomp,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($subtr0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtr1,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr1,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtr2,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr2,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subtr4,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($imptr4,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($subts0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impts0,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subts4,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impts4,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($subts8,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impts8,2) ?></font></td>
   <td align="center"><font size=1 ></font></td> 
   <td align="right"><font size=1 ><?php echo number_format($subg13,2) ?></font></td>
   <td align="right"><font size=1 ><?php echo number_format($impg13,2) ?></font></td>
 </tr>
  <?PHP   
	$contador++;
	} //fin while


?>
   </tr>
 <tr>
   <td></td>
   <td align="left"><strong><font size=1 >Subtotal Comprobantes </font></strong></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotexecom ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotgracom  ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalcom,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotaldescom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php  echo number_format($subtotalimpcom ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalgrancom,2) ?></font></strong></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <!-- /******REDUCIDA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr0com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr1com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr2com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr4com,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr4com,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td>    
   <!-- /******TRANSITORIA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts0com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts4com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts8com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts8com ,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td> 
    <!-- /******GENERAL************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subg13com ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impg13com ,2) ?></font></strong></td>  

 </tr>

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

</table>




<?php 



	  $consulta2 = "SELECT  SUM(x.totdes) AS totdes, SUM(x.subtotgra) AS subtotgra,
 SUM(x.subtotexe) AS subtotexe, SUM(x.subtotal) AS subtotal, SUM(x.monimp) AS monimp, SUM(x.imptr0) AS imptr0,
 SUM(x.imptr1) AS imptr1, SUM(x.imptr2) AS imptr2, 
 SUM(x.imptr4) AS imptr4, SUM(x.impts4) AS impts4, SUM(x.impts0) AS impts0,
 SUM(x.impts8) AS impts8, SUM(x.impg13) AS impg13, SUM(x.subtr0) AS subtr0, SUM(x.subtr1) AS subtr1,
 SUM(x.subtr2) AS subtr2, SUM(x.subtr4) AS subtr4, SUM(x.subts0) AS subts0, SUM(x.subts4) AS subts4,
 SUM(x.subts8) AS subts8, SUM(x.subg13) AS subg13, SUM(x.totcomp) AS totcomp
 FROM mensaje_receptor x ,tipo_cxp z 
WHERE  x.cdgcxp=z.cdgcxp AND  x.tipcom = 'FAC'   AND ".$where."  ORDER BY x.fecmen,x.cdgcxp ASC";

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

  	 while ($dato = $resultado2->fetch_assoc()) {
  						
		$subtotgraT  = $dato["subtotgra"];
		$subtotexeT  = $dato["subtotexe"];
        $subtotalT   = $dato["subtotal"];
        $totdesT     = $dato["totdes"];	
        $monimpT     = $dato["monimp"];
		$totcompT    = $dato["totcomp"];
		

		
				/******IMPUESTOS************/
        $imptr0T     = $dato["imptr0"];
		$imptr1T     = $dato["imptr1"];
		$imptr2T     = $dato["imptr2"];
		$imptr4T     = $dato["imptr4"];	
		$impts0T     = $dato["impts0"];
		$impts4T     = $dato["impts4"];
		$impts8T     = $dato["impts8"];
		$impg13T     = $dato["impg13"];
		/******SUBTOTALES************/
		$subtr0T     = $dato["subtr0"];
		$subtr1T     = $dato["subtr1"];
		$subtr2T     = $dato["subtr2"];
		$subtr4T     = $dato["subtr4"];	
		$subts0T     = $dato["subts0"];
		$subts4T     = $dato["subts4"];
		$subts8T     = $dato["subts8"];
		$subg13T     = $dato["subg13"];
					
	
	} 
	?>
<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"><strong><font size=1 >TOTAL FACTURACION</font></strong></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="left"><strong><font size=1 >&nbsp;</font></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotexeT ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotgraT  ,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($subtotalT,2)?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($totdesT ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php  echo number_format($monimpT ,2) ?></font></strong></td>
   <td align="right"><strong><font size=1 ><?php echo number_format($totcompT,2) ?></font></strong></td>
    <td align="left"><strong><font size=1 >&nbsp;</font></td>
   <!-- /******REDUCIDA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr0T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr0T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr1T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr1T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr2T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr2T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subtr4T,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($imptr4T,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td>    
   <!-- /******TRANSITORIA************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subts0T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts0T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts4T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts4T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($subts8T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impts8T ,2) ?></font></strong></td>
   <td align="center"><font size=1 ></font></td> 
    <!-- /******GENERAL************/-->
    <td align="right"><strong><font size=1 ><?php echo number_format($subg13T ,2) ?></font></strong></td>
    <td align="right"><strong><font size=1 ><?php echo number_format($impg13T ,2) ?></font></strong></td>  

 </tr>
</table>     
<?php 	
 }  
   
?>
</body>
</html>