<?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="4"><img src="../img/Logo_reportes.png"  /></td>
        <td width="87%"><font color="red" 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="22"><font size=2 >Numero de Telefono '.$Telefono.'</font></td>
      </tr>
    </table>';
  
   

	 $cdgfam=$_GET["Familia"];
	 $cdglin=$_GET["Linea"];

	$where="1=1";
if ($cdglin <> "") { $where.=" AND cdglin='$cdglin'"; }
if ($cdgfam <> "") { $where.=" AND cdgfam='$cdgfam'"; }

				
	 
	 if ($cdgfam=="") {
	 
	$dscfam="TODAS LAS FAMILIAS";
	 
	     } else {

		
					$query_facturas = "SELECT * FROM familias WHERE cdgfam=$cdgfam ";
					$rs_facturas = $mysqli->query($query_facturas);
					$row = $rs_facturas->fetch_assoc();
					
					$dscfam = $row["dscfam"];
		
		
     }	
	 

	 
	 if ($cdglin=="") {
	 
	$dsclin="TODAS LAS LINEAS";
	 
	     } else {

		
					$query_facturas2 = "SELECT * FROM Lineas WHERE cdglin=$cdglin ";
					$rs_facturas2 = $mysqli->query($query_facturas2);
					$row = $rs_facturas2->fetch_assoc();
					
					$dsclin = $row["dsclin"];
		
		
     }	
	 
	 $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 de Inventario por Familia '.$dscfam.' </strong></font></td>
      </tr>
      <tr>
        <td height="14" colspan="3" align="center"><font size="3" ><strong>Reporte Inventario por Linea '.$dsclin.' </strong></font></td>
      </tr>
  </table>
  ';
	
	
	 $codigoHTML.='
<table width="100%" role="rows" cellpadding="0" cellspacing="0" border="1">
    <tr>
    
        <td width="8%"  align="center"bgcolor="#CCCCCC" ><font size=1 ><strong>Codigo</strong></font></td>
    
		<td width="59%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Articulo</strong></font></td> 
	    <td width="23%" align="right" bgcolor="#CCCCCC"><div align="right"><font size=1 ><strong>Existencia</strong></font></div></td>
    </tr>
  </table>
';
   
   								   					
				$consulta = "SELECT * FROM web_1001  WHERE  estart=1  AND ".$where. "  ORDER BY  cdgfam,  dscart ASC   " ;
				if ($resultado = $mysqli->query($consulta)) 

 
  			   while ($fila = $resultado->fetch_assoc()) {		
					       
						    $cdgart   = $fila["CDGART"];
							$cdgbar   = $fila["CDGBAR"];
							$dscart   = $fila["DSCART"];
							$cdgfam   = $fila["CDGFAM"];  
							$exiact   = $fila["EXIACT"];  
							$dscart = substr($dscart, 0, 80);		
				 	

$codigoHTML.='
   <table width="100%"  rules="none" border="0">
    
      <tr>

        <td width="10%">  <font size=1 >'.$cdgbar.'</font></td>
   	    <td width="70%">  <font size=1 align="right">'.$dscart.'</font></td>
		<td width="20%" align="right"> <font size=1 >'.number_format($exiact, 2).'</font>  <font size=1 ></font>  </td>
	  </tr>
  </table>
   ';

  	        
		 } 
   
	
	 
				 $codigoHTML.='
   <table width="100%"  rules="none" border="0">

  </table>';
  	
	
$codigoHTML.='
   <table width="100%" height="15" role="rows" cellpadding="0" cellspacing="0" border="1">
     <tr>
       <td height="15">&nbsp;</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);
$dompdf->render();
// add the header
//$canvas = $dompdf->get_canvas();
//$font = Font_Metrics::get_font("helvetica", "bold");
//
//// the same call as in my previous example
//$canvas->page_text(745, 555, "Pagina : {PAGE_NUM} de {PAGE_COUNT}",
//                   $font, 8, array(0,0,0));

ini_set("memory_limit","7000M");

$dompdf->stream("Lista de Inventario.pdf", array("Attachment" => false));
 


?>
