<?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");


$tgl1     = $_GET['tgl_awal'];
$explode  = explode('-',$tgl1);
$tgl_awal = $explode[2]."-".$explode[1]."-".$explode[0];

$tgl2      = $_GET['tgl_akhir'];
$explode   = explode('-',$tgl2);
$tgl_akhir = $explode[2]."-".$explode[1]."-".$explode[0];

if (isset($_GET['tgl_awal'])) {
    $no    = 1;
    
    $query = mysqli_query($mysqli, "SELECT d.id as 'folio',a.tipo_transaccion, 
	                                a.codigo_transaccion, a.fecha,a.codigo,a.numero,b.codigo,b.nombre,a.observaciones,c.username,a.status 
									FROM transaccion_medicamentos as a INNER JOIN medicamentos as b ON a.codigo=b.codigo 
									INNER JOIN usuarios as c on a.created_user = c.id_user 
									INNER JOIN transaccion_medicamentos_enc as d on d.id = a.idenc 
									WHERE a.fecha BETWEEN '$tgl_awal' AND '$tgl_akhir'
									AND a.tipo_transaccion = 'Entrada'
									ORDER BY codigo_transaccion ASC") 
                                    or die('error '.mysqli_error($mysqli));
    $count  = mysqli_num_rows($query);
}

//Query parametros perfil
$queryperfil = mysqli_query($mysqli, "SELECT * FROM perfil")
                                or die('error'.mysqli_error($mysqli));
$rows  = mysqli_num_rows($queryperfil);
$data_perfil  = mysqli_fetch_assoc($queryperfil);
$folio_perfil = $data_perfil['folio'];
$nombre_perfil = $data_perfil['nombre_empresa'];
$direccion_perfil = $data_perfil['direccion'];
$direccion_perfil = $data_perfil['direccion'];
$email_perfil = $data_perfil['email'];
$almacen_perfil = $data_perfil['almacen'];
$almacenista_perfil = $data_perfil['almacenista'];
?>
<html xmlns="http://www.w3.org/1999/xhtml"> 
   
    <body>
        <div id="title">
           
        </div>
    <?php  
    if ($tgl_awal==$tgl_akhir) { ?>
        <div id="title-tanggal">
             Fecha <?php echo tgl_eng_to_ind($tgl1); ?>
        </div>
    <?php
    } else { ?>
	 
        <div id="title-tanggal">
		<?php
		/*	echo "<img src='http://".$_SERVER['HTTP_HOST']."/images/logo.png' border='0' width='250' height='110' align=\"center\"><br>";	*/
			 
			 ?>
           Reporte de entradas y salidas por transaccion desde <?php echo tgl_eng_to_ind($tgl1); ?> hasta <?php echo tgl_eng_to_ind($tgl2); ?>
		   
        </div>
    <?php
    }
    ?>
        
        <hr><br>
        <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>NO.</small></th>
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>ENTRADA</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>TRANSACCION No </small></th>
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>ESTATUS</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>FECHA</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>CÓDIGO </small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>NOMBRE DE PRODUCTO</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>TIPO </small></th>
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>MOTIVO </small></th>
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>CANT. </small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:10px;"><small>AUTORIZA</small></th>
						<!--<th height="20" align="center" valign="middle"><small>OBSERVACIONES</small></th>-->
                    </tr>
                </thead>
                <tbody>
<?php
    
    if($count == 0) {
        echo "  <tr>
                    <td width='40' height='13' align='center' valign='middle'style='font-size:70%;'></td>
					<td width='100' height='13' align='center' valign='middle'style='font-size:70%;'></td>
                    <td width='120' height='13' align='center' valign='middle'style='font-size:70%;'></td>
                    <td width='80' height='13' align='center' valign='middle'style='font-size:70%;'></td>
                    <td width='80' height='13' align='center' valign='middle'style='font-size:70%;'></td>
                    <td style='padding-left:5px;' width='155' height='13' valign='middle'style='font-size:70%;'></td>
					<td style='padding-left:5px;' width='50' height='13' valign='middle'style='font-size:70%;'></td>
                    <td style='padding-right:10px;' width='50' height='13' align='right' valign='middle'style='font-size:70%;'></td>
                    <td width='120' height='13' align='center' valign='middle'style='font-size:70%;'></td>
					<td width='130' height='13' align='center' valign='middle'style='font-size:70%;'></td>
					<td width='130' height='13' align='center' valign='middle'style='font-size:70%;'></td>
                    <!--<td width='130' height='13' align='center' valign='middle'></td>-->
					
					
                </tr>";
    }

    else {
   
        while ($data = mysqli_fetch_assoc($query)) {
            $tanggal       = $data['fecha'];
            $exp           = explode('-',$tanggal);
            $fecha = $exp[2]."-".$exp[1]."-".$exp[0];

            echo "  <tr>
                        <td width='40' height='13' align='center' valign='middle'style='font-size:70%;'>$no</td>
						<td width='60' height='13' align='left' valign='middle'style='font-size:70%;'>$folio_perfil-$data[folio]</td>
                        <td width='100' height='13' align='center' valign='middle'style='font-size:70%;'>$data[codigo_transaccion]</td>
						<td width='60' height='13' align='center' valign='middle'style='font-size:90%;'>$data[status]</td>
                        <td width='60' height='13' align='center' valign='middle'style='font-size:70%;'>$fecha</td>
                        <td width='60' height='13' align='center' valign='middle'style='font-size:70%;'>$data[codigo]</td>
                        <td style='padding-left:5px;' width='255' height='13' valign='middle'style='font-size:70%;'>$data[nombre]</td>
						<td style='padding-left:5px;' width='50' height='13' valign='middle'style='font-size:70%;'>$data[tipo_transaccion]</td>
						<td width='100' height='13' align='center' valign='middle'style='font-size:70%;'>$data[observaciones]</td>
                        <td style='padding-right:10px;' width='30' height='13' align='center' valign='middle'style='font-size:70%;'>$data[numero]</td>
                        <td width='100' height='13' align='center' valign='middle'style='font-size:70%;'>$data[username]</td>
						
                    </tr>";
            $no++;
        }
    }
?>	
                </tbody>
            </table>

        </div>
    </body>
</html>
<?php
$filename="datos de registro de prodcutos.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('L','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; }
?>