<?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"];
	   
	   $total    = 0;
	   $contador = 0;

  
$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="84%"><font color="blue" size=4><strong>'.$NombreComercial.'</strong></font></td>
      </tr>
      <tr>
        <td height="12"><font size=2 >'.$razsoc.'</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>
       
      </tr>
      <tr>
        <td height="22">&nbsp;</td>
      </tr>
    </table>
    ';
   
	
					
						
	 
	 $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 Costo de Inventario </strong></font></td>
      </tr>

    </table>
  ';
	
	
	 $codigoHTML.='
<table width="100%" role="rows" cellpadding="0" cellspacing="0" border="1">
    <tr>
    
        <td width="20%"  align="center"bgcolor="#CCCCCC" ><font size=1 ><strong>Codigo</strong></font></td>
        <td width="20%" align="center" bgcolor="#CCCCCC" ><font size=1 ><strong>Barras</strong></font></td>
        <td width="100%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Descripcion</strong></font></td>
		<td width="20%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Existencia</strong></font></td>
        <td width="20%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Costo</strong></font></td>
        <td width="20%" align="center" bgcolor="#CCCCCC"><font size=1 ><strong>Total</strong></font></td>
      
 
      </tr>
	   </table>';
          

	
	    $consulta=("SELECT * FROM web_1001 WHERE EXIACT > 0 ORDER BY DSCART ASC");
		if ($resultado = $mysqli->query($consulta)) 
        $count = 0;
  	    while ($dato = $resultado->fetch_assoc()) {
	
				$cdgart = $dato['CDGART'];
				$cdgbar = $dato['CDGBAR'];
				$exiact = $dato['EXIACT'];
	            $pre001 = $dato['cosart'];
				$presub = $pre001 * $exiact ;
				$dscart = $dato['DSCART'];
				$dscart = substr($dscart, 0, 40);
			
	 $contador = $contador + 1 ;
	 $total    = $presub + $total;
		
           if($count == 0 )		
                $codigoHTML.='<table width="100%"  rules="none" border="0">';

            $codigoHTML.='    		

    
      <tr>
        <td width="10%">  <font size=1 >'.$cdgart.'</font></td>
        <td width="10%">  <font size=1 >'.$cdgbar.'</font></td>
   	    <td width="50%">  <font size=1 align="left">'.$dscart.'</font></td>
   	    <td width="10%" align="right">  <font size=1 >'.number_format($exiact,2).'</font></td>
		<td width="10%" align="right">  <font size=1 >'.number_format($pre001,2).'</font></td>
        <td width="10%" align="right">  <font size=1 >'.number_format($presub,2).'</font></td>

                  </tr> ';
              $count++;
       }
        if($count > 1) 
            $codigoHTML.='</table>';
 
			
$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="30%" height="12" align="left"><font size=2 >Cantidad de Articulos</font></td>
			 <td width="10%" align="right"><font size=1 >'.$contador.'</font></td>
			 <td width="20%" align="right"><font size=1 ></font></td>
			 <td width="20%" align="right"><font size=1 ></font></td>
			 <td width="20%" align="right"><font size=1 >TOTAL</font></td>
              <td width="20%" align="right"><font size=1 >'.number_format($total,2).'</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);

$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(490, 800, "Pagina : {PAGE_NUM} de {PAGE_COUNT}",
//                   $font, 8, array(0,0,0));

ini_set("memory_limit","70000M");
$dompdf->stream("Costo de Inventario.pdf", array("Attachment" => false));



		
?>
