<?php
session_start();
ob_start();


require_once "../../../config/database.php";

include "../../../config/fungsi_tanggal.php";

include "../../../config/fungsi_rupiah.php";

$hari_ini = date("d-m-Y");

$no = 1;

$query = mysqli_query($mysqli, "SELECT a.codigo,a.nombre,a.stock,concat('$',format(a.precio_compra2,2))as precio_compra2,concat('$',format((a.precio_compra2 * a.stock) ,2)) as 'costo_total',b.name_user
			FROM medicamentos a, usuarios b 
			where b.id_user = a.created_user
			ORDER BY a.nombre ASC")
                                or die('Error '.mysqli_error($mysqli));
$count  = mysqli_num_rows($query);
?>
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head>

		-->
		

        <link rel="stylesheet" type="text/css" href="../../assets/css/laporan.css" />
    </head>
    <body>
        <div id="title">
           Informe de stock del almacen
		    <?php
      echo "  con fecha  " . date("d") . "/" . date("m") . "/" . date("Y");
		   
		   ?>  


        </div>
        
        <hr><br>
<!---------------------------------  Tabla de articulos ------------------------------->
        <div id="isi">
		
            <table width="100%" border="0.3" cellpadding="0" cellspacing="0">
                <thead style="background:#e8ecee">
                    <tr class="tr-title">
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>#</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>COD</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>PRODUCTOS</small></th>
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>USUARIO QUE INGRESO</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>STOCK</small></th>
						<th height="50" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>PRECIO DE COMPRA</small></th>
						<th height="50" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>COSTO TOTAL</small></th>
						
                    </tr>
                </thead>
                <tbody>
        <?php
     
        while ($data = mysqli_fetch_assoc($query)) {
        #    $precio_compra = format_rupiah($data['precio_compra']);
         #   $precio_venta = format_rupiah($data['precio_venta']);
          
            echo "  <tr>
                        <td width='40' height='13' align='center' valign='middle'style='font-size:70%;'>$no</td>
						
                        <td width='50' height='13' align='center' valign='middle' style='font-size:70%;'>$data[codigo]</td>
                        <td style='padding-left:5px;' width='250' height='13' valign='middle' style='font-size:65%;'>$data[nombre]</td>
						<td width='100' height='13' align='center' valign='middle' style='font-size:60%;'>$data[name_user]</td>
                         <td style='padding-right:10px;' width='50' height='13' align='center' valign='middle' style='font-size:70%;'>$data[stock]</td>
                 
						<td width='90' height='13' align='center' valign='middle' style='font-size:60%;'>$data[precio_compra2]</td>
						<td width='80' height='13' align='center' valign='middle' style='font-size:60%;'>$data[costo_total]</td>
						
                    </tr>";
            $no++;
        }
        ?>  
                </tbody>
            </table>

            
       
		<!---------------------------------  fin Tabla de articulos ------------------------------->
		
		<!---------------------------------  Tabla de sumatoria ------------------------------->
		<?php
		$query2 = mysqli_query($mysqli, "SELECT CONCAT('$',FORMAT(SUM(precio_compra2 * stock),2)) as 'costo_total_almacen' FROM medicamentos")
                                or die('Error '.mysqli_error($mysqli));
								?> 
      
		
            <table width="100%" border="0.3" cellpadding="0" cellspacing="0">
                <thead style="background:#e8ecee">
                    <tr class="tr-title">
                        <th height="20" align="right" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>COSTO TOTAL DE ALMACEN</small></th>
                        
                    </tr>
                </thead>
                <tbody>
        <?php
      
        while ($data = mysqli_fetch_assoc($query2)) {
        #    $precio_compra = format_rupiah($data['precio_compra']);
         #   $precio_venta = format_rupiah($data['precio_venta']);
          
            echo "  <tr>
                        
                        <td width='692' height='13' align='right' valign='middle'>$data[costo_total_almacen]</td>
                        
                    </tr>";
            $no++;
        }
        ?>  
                </tbody>
            </table>

            
        </div>
		<!---------------------------------  fin Tabla de sumatoria ------------------------------->
		
		
    </body>
</html>
<?php
$filename="INFORMDE STOCK.pdf"; 
//==========================================================================================================
$content = ob_get_clean();
$content = '<page style="font-family: freeserif">'.($content).'</page>';

require_once('../../../assets/plugins/html2pdf_v4.03/html2pdf.class.php');
try
{
    $html2pdf = new HTML2PDF('P','F4','en', false, 'ISO-8859-15',array(10, 10, 10, 10));
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    $html2pdf->Output($filename);
}
catch(HTML2PDF_exception $e) { echo $e; }
?>