<?php
 header("content-type: application/xls");
  header("content-disposition: attachment; filename= Reporte_Folio.xls");

?>

<?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 CONCAT(serie,id) as folio,
									a.fecha,
									a.nombre, 
									a.observacion_enc,
									b.username,
									c.tipo_transaccion,
									a.status
									FROM transaccion_medicamentos_enc as a , usuarios as b, transaccion_medicamentos as c
                                    /*WHERE a.fecha BETWEEN '20190101' AND '20190121'*/
                                    WHERE a.fecha BETWEEN '$tgl_awal' AND '$tgl_akhir'
									and a.created_user = b.id_user
                                    and a.folio = c.idenc
                                    group by folio") 
                                    or die('error '.mysqli_error($mysqli));
    $count  = mysqli_num_rows($query);
}
?>
<html xmlns="http://www.w3.org/1999/xhtml"> 
    
    <body>
      
    <?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://localhost/inventario/images/logo.png' border='0' width='150' height='60' align=\"left\">";
			 
			 ?>
            Reporte de folios 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:15px;"><small>NO.</small></th>
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:15px;"><small>FOLIO</small></th> 
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:15px;"><small>ESTATUS</small></th> 
						<th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:15px;"><small>TIPO</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:15px;"><small>FECHA</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:15px;"><small>RECIBE</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:15px;"><small>AUTORIZA</small></th>
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;font-size:15px;"><small>OBSERVACIONES</small></th>
					
                    </tr>
                </thead>
                <tbody>
<?php
    
    if($count == 0) {
        echo "  <tr>
                    <td width='40' height='30' align='center' valign='middle'></td>
					<td width='80' height='13' align='center' valign='middle'></td>
                    <td width='120' height='13' align='center' valign='middle'></td>
                    <td width='80' height='13' align='center' valign='middle'></td>
                    <td width='25' height='13' align='center' valign='middle'></td>
                    <td style='padding-left:5px;' width='650' height='13' 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='30' align='center' valign='middle'style='font-size:90%;'>$no</td>
						<td width='130' height='13' align='center' valign='middle'style='font-size:90%;'>$data[folio]</td>
						<td width='130' height='13' align='center' valign='middle'style='font-size:90%;'>$data[status]</td>
						<td width='80' height='13' align='center' valign='middle'style='font-size:90%;'>$data[tipo_transaccion]</td>
						<td width='80' height='13' align='center' valign='middle'style='font-size:90%;'>$fecha</td>
                        <td width='120' height='13' align='center' valign='middle'style='font-size:90%;'>$data[nombre]</td> 
                        <td width='120' height='13' align='center' valign='middle'style='font-size:90%;'>$data[username]</td> 
                        <td style='padding-left:5px;' width='310' height='13' valign='middle'style='font-size:90%;'>$data[observacion_enc]</td>
					
                    </tr>";
            $no++;
        }
    }
?>	
                </tbody>
            </table>

        </div>
    </body>
</html>