<?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>

</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>
<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"];

 
 
$codigoHTML='
    <table width="100%"  cellpadding="0" cellspacing="0"  border="0">
      <tr>
        <td width="13%" rowspan="5"><img src="../img/logo.jpg" /></td>
        <td width="87%"><font color="blue" size=4><strong>'.$NombreComercial.'</strong></font></td>
      </tr>
      <tr>
        <td height="12"><font size=2 >Cedula '.$Cedula.'</font></td>
      </tr>
      <tr>
        <td height="12"><font size=2 >'.$Direccion.'</font></td>
      </tr>
      <tr>
        <td height="11"><font size=2 >Numero de Telefono '.$Telefono.'</font></td>
      </tr>
      <tr>
        <td height="22">&nbsp;</td>
      </tr>
    </table>
    ';
  
   
	 $fecini=$_GET["fechainicio"];
	 $fecfin=$_GET["fechafin"];


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

					
						
	 
	 $codigoHTML.='
  <table width="100%" height="16%" border="1" cellpadding="0" cellspacing="0" >
      <tr>
        <td width="100%" height="21" colspan="3" align="center"><font size=3 ><strong>Reporte Recibos de Pago a Proveedores</strong></font></td>
      </tr>
      <tr>
        <td height="14" colspan="3" align="center">Fecha del <font size="2" >'.$fecini.'</font> al <font size="2" >'.$fecfin.'</font></td>
      </tr>
    </table>
  ';
	
	
	 $codigoHTML.='
<table width="100%" role="rows" cellpadding="0" cellspacing="0" border="1">
    <tr>
    
        <td width="13%"  align="center"bgcolor="#CCCCCC" ><font size=1 ><strong>Recibo</strong></font></td>
        <td width="19%" align="center" bgcolor="#CCCCCC" ><font size=1 ><strong>Fecha</strong></font></td>
        <td width="75%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Cliente</strong></font></td>
		<td width="10%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Cajero</strong></font></td>
        <td width="20%" align="right" bgcolor="#CCCCCC"><font size=1 ><strong>Abono</strong></font></td>
        <td width="20%" align="right" bgcolor="#CCCCCC"><font size=1 ><strong>Interes</strong></font></td>
          <td width="20%" align="right" bgcolor="#CCCCCC"><font size=1 ><strong>Total</strong></font></td>

 
      </tr>
	   </table>';
          
   								   					
	$consulta = "SELECT * FROM pagos_proveedores WHERE  fecrec  between '$fechainicio' AND '$fechafin'  ORDER BY numrec ASC" ;
	if ($resultado = $mysqli->query($consulta)) 
     $count = 0;
 
  			   while ($dato = $resultado->fetch_assoc()) {		
 
				$numrec = $dato['numrec'];
				$fecrec = $dato['fecrec'];
 				$fecrec = implode("-", array_reverse(explode("-", $fecrec))); 		
				$cdgpro = $dato['cdgpro'];
				$dscpro = $dato['dscpro'];
				$dscpro = substr($dscpro, 0, 40);
				$cdgcaj = $dato['cdgcaj'];
				$monabo = number_format($dato['monabo'], 2);
				$monint = number_format($dato['monint'], 2);
				$montot = number_format($dato['montot'], 2);
			
  if($count == 0 )		
                $codigoHTML.='<table width="100%"  rules="none" border="0">';

            $codigoHTML.='   
    
      <tr>
        <td width="15%">  <font size=1 >'.$dato['numrec'].'</font></td>
        <td width="18%">  <font size=1 >'.$fecrec.'</font></td>
   	    <td width="10%">  <font size=1 align="right">'.$dato['cdgpro'].'</font></td>
   	    <td width="65%">  <font size=1 align="left">'.$dscpro.'</font></td>
		<td width="10%">  <font size=1 align="center">'.$cdgcaj.'</font></td>
        <td width="20%" align="right">  <font size=1 >'.$monabo.'</font></td>
        <td width="20%" align="right">  <font size=1 >'.$monint.'</font></td>
		<td width="20%" align="right">  <font size=1 >'.$montot.'</font></td>
      </tr>
      
   </tr> ';
              $count++;
       }
        if($count > 1) 
            $codigoHTML.='</table>';
  
  	          
			   	$consulta2 = "SELECT  SUM(monabo) AS totalabono, SUM(montot) AS totalmonto , SUM(monint) AS totalinteres FROM pagos_proveedores WHERE fecrec  between '$fechainicio' AND '$fechafin' " ;
	if ($resultado2 = $mysqli->query($consulta2)) 

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

				$totalabono   = number_format($dato2['totalabono'], 2);
				$totalinteres = number_format($dato2['totalinteres'], 2);
				$totalmonto   = number_format($dato2['totalmonto'], 2);
			
			
$codigoHTML.='
   <table width="100%" height="15" role="rows" cellpadding="0" cellspacing="0" border="1">
     <tr>
       <td height="15"><table width="100%" border="0" cellpadding="0" cellspacing="0">
         <tr>
            <td width="120%" height="12" align="left"><font size=2 > TOTALES FINALES</font></td>

               <td width="20%" align="right"><font size=1 >'.$totalabono.'</font></td>
			  <td width="20%" align="right"><font size=1 >'.$totalinteres.'</font></td>
              <td width="20%" align="right"><font size=1 >'.$totalmonto.'</font></td>
         </tr>
       </table></td>
     </tr>
   </table>
   <p>';
   
     } 
$codigoHTML.='

   </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("Estado de Cuenta.pdf", array("Attachment" => false));


?>
