<?php session_name('CAKEPHP'); session_start();
error_reporting(true);
$PageSecurity = 11;
include('includes/DefinePOClass.php');
include('includes/DefineSerialItems.php');
include('includes/SQL_CommonFunctions.inc');
$title = _('Compensation Leave Details');
$PageName ='Compensation Leave Details'; 
?>
<script language="javascript" type="text/javascript">
function validate_branch()
{
  $branch = $('#site').val();
  if($branch == "")
  {
    alert("Select Branch");
    return false;
  }
  return true;
}




</script>
  <link rel="stylesheet" href="css/new_mxerp.css">
  <form method="post" action="">
      <h2 align="center">Compensation Leave Details</h2>
      <table width="100%" align="center" class="" border="1" cellspacing="0" cellpadding="2" style="border-collapse:collapse;">
          <tr>
            <td class="tabledata"><strong>Branch</strong></td>
            <td class="tabledata">
              <select name="site" id="site" onChange="showVendor(this.value)"> 
                <option value="">Select</option>
                    <?php  $ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')";
                           $site_sql=DB_query($ss1,$db);
                           while($site_row=DB_fetch_array($site_sql))
                           {
                              $p='';
                              if($site_row['loccode'] == $_POST['site'])  
                                  $p="selected";?>
                              <option value="<?php echo $site_row['loccode']; ?>" <?php echo $p;?>><?php echo $site_row['locationname']; ?></option>
                     <?php } ?>
               </select>
            </td>
            <td class="tabledata"><strong>Emp</strong></td>
            <td class="tabledata">
              <select name="emp" id="emp" style="width:150px;">
                <option value="">All</option>
                  <?php $SQLEmp=DB_query("select * from empmaster",$db); 
                  while($Emp=DB_fetch_array($SQLEmp))
                  { ?>
                    <option value="<?php echo $Emp['id']; ?>">
                      <?php echo $Emp['emp_name']; ?>
                    </option>
            <?php } ?>  
            </select>
            </td>
           <td class="tabledata">Month</td>
           <td class="tabledata">
             <select name="month" id="month" style="width:150px;">
             <option value="0">Select</option>
             <?php $amonth=array(1=>'Jan','Feb','March','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
              for($i=1;$i<=count($amonth) ;$i++)
              {
                $p='';
                if($_REQUEST['month']==$i)
                    $p='selected';
                echo "<option value='".$i."' $p>$amonth[$i]</option>";
              }
              ?>
            </select>
           </td>
           <td class="tabledata">Year</td>
            <td class="tabledata">
              <select name="year">
              <option value="0">Select</option>
                <?php 
                  for($i=date('Y');$i>=2000;$i--)
                  {
                ?>
                  <option value="<?php echo $i;?>"><?php echo $i;?></option>
                <?php } ?>
             </select>
            </td>
        </tr>
        <tr><td align="center" style="text-align:center;" colspan="14"> <input type="submit" name="view" value="search" class="search" onclick="return validate_branch();"></td></tr>
  </table>

</form>
<?php 
  if($_REQUEST['view']!='')
  {
      $query = "SELECT empmaster.id as empid,empmaster.*, attendance_complesation.* FROM empmaster,attendance_complesation
                WHERE empmaster.id = attendance_complesation.emp_id  and ";
      
      $filter=array();
       if($_REQUEST['site']!='')
          $filter[]=" empmaster.emp_site='".$_REQUEST['site']."'";

       if($_REQUEST['emp']!='')
          $filter[]=" empmaster.id ='".$_REQUEST['emp']."'";
      if($_REQUEST['month']!='0')
          $filter[]=" attendance_complesation.month ='".$_REQUEST['month']."'";
      if($_REQUEST['year']!='0')
          $filter[]=" attendance_complesation.year ='".$_REQUEST['year']."'";

      $query.= implode(" and ",$filter);
     // echo $query;

 }

?>
<?php if($_REQUEST['view']!='')
{
?>
  <p align="right"><a href="compensationleavedetailsprint.php" target="_blank">Print </a></p>
  <div style="width:auto; height:auto; margin-left:auto; margin-right:auto;">
      <div align="center"><strong><?php echo $message; ?></strong> </div><br/>
      <table width="100%" cellpadding="3" cellspacing="0" border="1" style="border-collapse:collapse;">
      <tr bgcolor="#999999">
          <td width="3%"><strong>S. No.</strong></td>
          <td ><strong>Date</strong></td>
          <td ><strong>Reason</strong></td>
          <td ><strong>Status</strong></td>
      </tr>
  <?php 
      $result=DB_query($query,$db);
      $count=DB_num_rows($result);
      if(DB_num_rows($result)>0)
      {
        $i=1;
        $emp_name = '';
        $pending=0;
        $adjust=0;
        $employes_leave="";

        while($myrow=DB_fetch_array($result))
        { 
            if($emp_name!=$myrow['emp_name'])
            { 
                $i=1;
                $emp_name = $myrow['emp_name']; 
                $emp_dtls = $myrow['empid']." - ".$myrow['emp_name'];
            ?>
              <tr>
                  <td colspan="5" align="left"><?php echo $emp_dtls; ?></td>
              </tr>
            <?php }
           
          ?>
        <tr>
          <td><?php echo $i; ?></td>
           <td><?php echo $comdate= ConvertSQLDate($myrow['comp_date']) ; ?></td>
          <td><?php echo $reason = $myrow['reason']; ?></td>
          <td>
              <?php 
             
              $status="";
              if($myrow['com_status']=='Y')
              {
                  $datedata = DB_query("SELECT attendance_date FROM daily_attendance WHERE adjust_date = '".$myrow['comp_date']."'  AND employee = '".$myrow['empid']."' limit 1",$db);
                   while($myrow=DB_fetch_array($datedata))
                      $adjtDate = ConvertSQLDate($myrow['attendance_date']);
                  
                  $status = "Adjusted"." ( ".$adjtDate." )";
                  echo $status;
                  
              }
              else
              {
                $status="Pending";
                  echo $status;
              }
                ?>
          </td>
          
          </tr>
  <?php 
        $employes_leave[] =array($emp_dtls,$i,$comdate,$reason,$status);
  $i++;
   }
      }
      else
      {
        echo "<tr><td colspan='4' style='text-align:center'>No Record Found</td></tr>";
      }
      $_SESSION['employes_leave'] = $employes_leave;
}

?>
 
</table>
</div>
