<?php 

include ("../conexion.php");
    
require_once '../dompdf/autoload.inc.php';


require_once '../dompdf/lib/html5lib/Parser.php';
require_once '../dompdf/lib/php-font-lib/src/FontLib/Autoloader.php';
require_once '../dompdf/lib/php-svg-lib/src/autoload.php';
require_once '../dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();

use Dompdf\Dompdf;



$codigoHTML='
<!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>Lista</title>
<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">

</head>


   <script type="text/php">

        if ( isset($pdf) ) {

          $font = Font_Metrics::get_font("helvetica", "bold");
          $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));

        }
  

</script>

	    <style type="text/css">      
		tabla {
  border-collapse: separate;
  border-spacing:  3px;
}
 </style>
<body>
<div align="center">
  <p>&nbsp;</p>';
  
       $parametros = "SELECT * FROM web_0000 ";
       $result_parametros = $mysqli->query($parametros);
       $row_para = $result_parametros->fetch_array();
     
	   $NombreComercial =  $row_para["NOMCOM"];
	   $razsoc          =  $row_para["RAZSOC"];
	   $Direccion       =  $row_para["DIREMP"];
	   $Cedula          =  $row_para["CEDJUR"];
	   $Telefono        =  $row_para["NUMTEL"];
  
     $fecini    = $_GET["fechainicio"];
	 $cdgtipven = $_GET["combotipoventa"];
	 $cdgcaj    = $_GET["cdgcaj"];
	 

	 
	 
	 $dia=1;
 	 $fecha_final= "+".$dia." day" ;
	 $feccie = strtotime ( $fecha_final , strtotime ( $fecini) ) ;
	 $fecfin = date ( 'Y-m-d' , $feccie );


$where = "1=1";	 
if ($cdgcaj <> "") { $where.=" AND cdgcaj='$cdgcaj'"; }
//if ($cdgtipven <> "") { $where.=" AND cdgtipven='$cdgtipven'"; }


		 

 $consulta2= ("SELECT  Sum(totalfactura) AS totalfactura , Sum(impser) AS impser , Sum(tot_sin_impser) AS tot_sin_impser  FROM impuesto_servicio WHERE tipmov != 'NC' ");

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

 
  	 while ($dato = $resultado2->fetch_assoc()) {
  						
	 $totalventas=$dato["totalfactura"];
	 $totalimpuesto=$dato["impser"];
	 $total_sin_impser=$totalventas - $totalimpuesto ;

  }
  
  
   $consultanotas= ("SELECT  Sum(totalfactura) AS totalfactura , Sum(impser) AS impser , Sum(tot_sin_impser) AS tot_sin_impser  FROM impuesto_servicio WHERE tipmov = 'NC' ");

		if ($resultadonotas = $mysqli->query($consultanotas)) 

 
  	 while ($dato = $resultadonotas->fetch_assoc()) {
  						
	 $totalnotas=$dato["totalfactura"];
	 $totalimpuestonotas=$dato["impser"];
	 $total_sin_impser_notas=$totalnotas - $totalimpuestonotas ;

  }


 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"];
		
		
     }
	 
	 $grantotalventas = $totalventas-$totalnotas;
	 $grantotalimpuesto =   $totalimpuesto - $totalimpuestonotas;
	 $grantotal_sin_impser= $total_sin_impser -$total_sin_impser_notas;
 
$codigoHTML='
  <table width="100%"  cellpadding="0" cellspacing="0"  border="0">
      <tr>
        <td width="22%" align="" rowspan="5"><img src="../img/logo.jpg" /></td>
        <td width="56%" align="center"><font color="blue" size=4><strong>'.$NombreComercial.'</strong></font></td>
        <td width="22%">&nbsp;</td>
      </tr>
      <tr>
        <td height="12" align="center"><font size="2" >Reporte Impuesto de Servicio </font></td>
        <td height="12">&nbsp;</td>
      </tr>
      <tr>
        <td height="12" align="center"><font size="2" >Del '.$fecini.' a partir de las 07:00:00 AM</font></td>
        <td height="12">&nbsp;</td>
      </tr>
      <tr>	 
        <td height="12" align="center"><font size=2 > Hasta las 07:00:00 AM del '.$fecfin.' </font></td>
        <td height="12">&nbsp;</td>
      </tr>
      <tr>
        <td height="12" align="center"><font size=2 ></font><font size="3" ><strong>Cajero: '.$cdgcaj.' - '.$nomcomusu.'</strong></font></td>
        <td height="12">&nbsp;</td>
      </tr>
    </table>
    ';
  
   

	 

	 
	 $codigoHTML.='
  
  ';
	
	
    $codigoHTML.='</p>
    <hr  color="#000000"/>
    <table cellspacing="0" align="center" cellpadding="0" style=" border-width: 2px;"  width="55%" border="1" bordercolor="#000000">
      <tr>
        <td colspan="4"  align="center" bgcolor="#CCCCCC" class="titulo"><strong><em>IMPUESTO DE SERVICIO</em></strong></td>
      </tr>
      <tr>
        <td width="4%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td width="50%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td width="41%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td width="5%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Monto Subtotal</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" > '.number_format($grantotal_sin_impser,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Impuesto de Servicio</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($grantotalimpuesto,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>

      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td colspan="2"  style="padding-bottom: 1px; border:0px solid black;">_________________________________________________________________</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">TOTAL FACTURADO</td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($grantotalventas,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
     

      
  </table>';
  
  	          
			  // $consulta=mysql_query("SELECT SUM(SALACT)AS ACTUAL, SUM(TOTNET) AS INICIAL FROM web_2101 WHERE CDGCLI=$Cdgcli");
     //   while($dato=mysql_fetch_array($consulta)){
			//	$INICIAL = number_format($dato['INICIAL'], 2);
			//	$ACTUAL  = number_format($dato['ACTUAL'], 2);
			
$codigoHTML.='
   
   <p>';
   
   //  } 
$codigoHTML.='

   </p>
   <p>&nbsp;</p>
   <p>&nbsp;</p>
  <table width="100%" border="0">
     <tr>
     </tr>
  </table>
   <p>&nbsp;</p>
</div>
</body>
</html>';

$codigoHTML=utf8_decode($codigoHTML);
$dompdf=new DOMPDF();
$dompdf->set_paper( "A4", "portrait" ); // a4,vertical
$dompdf->load_html($codigoHTML);
ini_set("memory_limit","256M");
$dompdf->render();
$dompdf->stream("Reporte Impuesto de Servicio.pdf", array("Attachment" => false));

?>