<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];

// Common Information

$page_title="Employee Leave Status";
$page="71_employee_leave_status.php?active_id=".$active_id."&menu_id=".$menu_id."";
$table='leave_details';	
$unique='id';

// End Common Information

?>

<!DOCTYPE html>
<html lang="en">

 <?php require_once('inc_files/inc_head.php'); ?>
 
 

<body>

  <!-- ======= Header ======= -->
  <?php 
  require_once('inc_files/inc_header.php');
  ?><!-- End Header -->
  
  <?php
  do_calander('#fdate');
  do_calander('#tdate');
  ?>

  <!-- ======= Sidebar ======= -->
  <?php  require_once('inc_files/inc_menu.php'); ?><!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
          <li class="breadcrumb-item">HR Management</li>
          <li class="breadcrumb-item active"><?php echo $page_title?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section">
      <div class="row">
        <div class="col-lg-12"> 

          <div class="card">
            <div class="card-body">
			<br>
            <form class="row g-3" action="" method="post" name="codz" id="codz">
   		       
			
	<table width="80%" border="0" align="center" style="background: #ebf5fb ;">
      
      
        <tr height="50">
          <td align="right">From Date :&nbsp;&nbsp;</td>
          <td align="left"><input type="text" name="fdate" id="fdate" class="form-control" style="width:150px;" value="<?php echo $_POST['fdate'];?>" /></td>
          <td width="15%" align="right">Type: &nbsp;&nbsp;</td>
          <td width="30%">
		  <select id="leave_type" name="leave_type"  class="form-select"    >
		  <option></option>
			
			<?php foreign_relation($conn,'leave_type','id','leave_type',$_POST['leave_type'],'1 order by id');?>
        	</select>
		  </td>
          <td width="22%" rowspan="6" align="center" ><strong>
            &nbsp;&nbsp;&nbsp;
            <button type="submit" name="run_data" id="run_data" class="btn btn-success rounded-pill btn-sm">&nbsp;<i class="bi bi-filter me-1"></i> Run Report&nbsp;&nbsp;</button>
          </strong></td>
        </tr>
        <tr height="50">
        <td width="17%" align="right">To Date :&nbsp;&nbsp;</td>
        <td width="16%" align="left"><input type="text" name="tdate" id="tdate" class="form-control" style="width:150px;" value="<?php echo $_POST['tdate'];?>" /></td>
        <td align="right">EMP NAME:&nbsp;&nbsp;</td>
        <td>
		 <?php
			 auto_complete_from_db_sql($conn,'SELECT concat(emp_code," :: ",emp_name), concat(emp_code," :: ",emp_name) FROM employee_info
			WHERE 1 order by emp_code','employee_name');
		?>
                  <input type="text" class="form-control" id="employee_name" name="employee_name" value="<?php echo $_REQUEST['employee_name']?>" >		</td>
        </tr>
    </table>
               
  </form>
  <br>
	
              <!-- Table with stripped rows -->
              <table width="100%" class="table table-sm" style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#ebf5fb;  border-top: 1px solid #CCCCCC;">
                    <th width="8%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">EMP Code </span></th>
                    <th width="27%"  scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">EMP Name </span></th>
                    <th width="9%"  scope="col">LV No </th>
                    <th width="13%" scope="col">lv date</th>
                    <th width="12%"  scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">Day</span></th>
                    <th width="12%"  scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;" >LV Type </span></th>
                  </tr>
                </thead>
                <tbody>
					<?php
					
					
 $employee_name = $_REQUEST['employee_name'];
  $employee=explode(' :: ',$employee_name);
   $employee_code=$employee[0];
  
if($employee_code!=''){
$employee_con=" and e.emp_code='".$employee_code."' ";
}


if($_POST['leave_type']!=''){
$leave_type_con=" and a.leave_type='".$_POST['leave_type']."' ";
}


if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and a.lv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';

	
		 $sql = "select id, leave_type from leave_type where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
		 $leave_type[$info->id]=$info->leave_type;
		}
			
					     $sql = 'select a.*, e.emp_name from '.$table.' a, employee_info e 
						 where  a.emp_code=e.emp_code '.$employee_con.$leave_type_con.$date_con.' order by a.emp_code, a.lv_date';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
	<?php if(isset($_POST['run_data'])){?>		
      <tr>
      <td><?php echo $data->emp_code;?></td>
      <td><?php echo $data->emp_name;?></td>
      <td><?php echo $data->lv_no;?></td>
      <td><?php echo date('d-M-y',strtotime($data->lv_date));?></td>
      <td><?php echo $dayname = date('l', strtotime($data->lv_date));?></td>
      <td><?php echo $leave_type[$data->leave_type];?></td>
      </tr>
				  <?php }}?>
                </tbody>
              </table>
              <!-- End Table with stripped rows -->

            </div>
          </div>

        </div>

        
      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <?php require_once('inc_files/inc_footer.php'); ?>
 <!-- ======= Footer ======= -->

</body>

</html>