<?php
include("../include/config.php");
$date0='';
$date00='';
$date1='';
$date2='';
$date1='';
$dat='';
$sdt1='';
$srdt1='';
$frdate1='';
$trdate1='';
$emp_id='';
$emp_id=$_REQUEST['emp'];
$yr=$_REQUEST['yr'];
$y1=$_REQUEST['yr1'];
$mon=$_REQUEST['mon'];
 $m1=$_REQUEST['mon1'];
/****************************/
 if(isset($_REQUEST['frmdate1']) && $_REQUEST['frmdate1']!=''){
$date1=$_REQUEST['frmdate1'];
$date1=explode("-",$date1);
$date1=$date1[2].'-'.$date1[1].'-'.$date1[0];
}
 if(isset($_REQUEST['todate_1']) && $_REQUEST['todate_1']!=''){
$dat=$_REQUEST['todate_1'];
$dat=explode("-",$dat);
$dat=$dat[2].'-'.$dat[1].'-'.$dat[0];
}
 if(isset($_REQUEST['singdate']) && $_REQUEST['singdate']!=''){
$sdt1=$_REQUEST['singdate'];
$sdt1=explode("-",$sdt1);
$sdt1=$sdt1[2].'-'.$sdt1[1].'-'.$sdt1[0];
}

?>
<div>
 <table width="98%" border="0" cellspacing="0" cellpadding="0">
      <tr>
      <th width="7%" align="left" valign="middle" class="tr_td">Emp No</th>
       <th width="6%" align="left" valign="middle" class="tr_td">Name</th>
      <!--<th width="6%" align="left" valign="middle" class="tr_td">Dept</th>
      <th width="10%" align="left" valign="middle" class="tr_td">Address</th>
      <th width="7%" align="left" valign="middle" class="tr_td">Ph No.</th> -->
      <th width="7%" align="left" valign="middle" class="tr_td">Basic Salary</th>
      <th width="4%" align="left" valign="middle" class="tr_td">DA</th>
      <th width="4%" align="left" valign="middle" class="tr_td">TA</th>
      <th width="3%" align="left" valign="middle" class="tr_td">Other</th>
	   <th width="4%" align="left" valign="middle" class="tr_td">No Of WRK </th>
      <th width="6%" align="left" valign="middle" class="tr_td">No Of Lvs</th>
      <th width="9%" align="left" valign="middle" class="tr_td">Sal To Be paid</th>
      <th width="10%" align="left" valign="middle" class="tr_td">DATE</th>
      <th colspan="8" align="left" valign="middle" class="tr_td">Option</th>
      </tr>
<?php
//$emp_qry="select * from tbl_employee where 1   ";

//$emps=mysql_query($emp_qry);
$dcnt=0;
	$adjacents = 3;
	$page=0;
	$query = "SELECT COUNT(*) as cn FROM tbl_employee where 1 ";
	
	if($emp_id!=''){
	$query.=" and id='".$emp_id."'";
	}
	if($sdt1!=''){
		$query.=" and Adddate='".$sdt1."'";
		}else{
		
			if($date1!=''){
			$query.=" and Adddate>='".$date1."'";
			}
			if($dat!=''){
			$query.="  and  Adddate<='".$dat."'";
			}
		}
	
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages['cn'];
	
	$targetpage = "hr-emp-list.php"; 	
	$limit = 10; 	
	
	if(isset($_GET['page']))
	{							
	$page = $_GET['page'];
	}
	if($page) 
	$start = ($page - 1) * $limit; 			
	else
	$start = 0;		
		
	$sql = "SELECT * FROM tbl_employee where 1 ";
	
	if($emp_id!=''){
	$sql.=" and id='".$emp_id."'";
	}
	if($sdt1!=''){
		$sql.=" and Adddate='".$sdt1."'";
		}else{
		if($date1!=''){
		$sql.=" and Adddate>='".$date1."'";
		}
		if($dat!=''){
		$sql.="  and  Adddate<='".$dat."'";
		}
	}
	$sql.= " order by id desc LIMIT $start, $limit";
	
	$emps = mysql_query($sql);
	

	if ($page == 0) $page = 1;					
	$prev = $page - 1;							
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$lpm1 = $lastpage - 1;						
	
	
	$pagination = "";
	if($lastpage > 1)
	{	
	$pagination .= "<div class=\"pagination\">";
	if ($page > 1) 
	$pagination.= "<a href=\"javascript:emp_det($prev)\">« previous</a>";
	else
	$pagination.= "<span class=\"disabled\">« previous</span>";	
	if ($lastpage < 7 + ($adjacents * 2))	
	{	
	for ($counter = 1; $counter <= $lastpage; $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"javascript:emp_det($counter)\">$counter</a>";					
	}
	}
	elseif($lastpage > 5 + ($adjacents * 2))	
	{
	if($page < 1 + ($adjacents * 2))		
	{
	for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
	}
	$pagination.= "...";
	$pagination.= "<a href=\"javascript:emp_det($lpm1)\">$lpm1</a>";
	$pagination.= "<a href=\"javascript:emp_det($lastpage)\">$lastpage</a>";		
	}
	elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
	{
	$pagination.= "<a href=\"javascript:emp_det(1)\">1</a>";
	$pagination.= "<a href=\"javascript:emp_det(2)\">2</a>";
	$pagination.= "...";
	for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"javascript:emp_det($counter)\">$counter</a>";					
	}
	$pagination.= "...";
	$pagination.= "<a href=\"javascript:emp_det($lpm1)\">$lpm1</a>";
	$pagination.= "<a href=\"javascript:emp_det($lastpage)\">$lastpage</a>";		
	}
	else
	{
	$pagination.= "<a href=\"javascript:emp_det(1)\">1</a>";
	$pagination.= "<a href=\"javascript:emp_det(2)\">2</a>";
	$pagination.= "...";
	for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"javascript:emp_det($counter)\">$counter</a>";					
	}
	}
	}
		
	if ($page < $counter - 1) 
	$pagination.= "<a href=\"javascript:emp_det($next)\">next »</a>";
	else
	$pagination.= "<span class=\"disabled\">next »</span>";
	$pagination.= "</div>\n";		
	}
if($total_pages['cn']>0){
$c=0;
while($result=mysql_fetch_array($emps))
{
	$cmonth=date('m');
	$cyear=date('y');
	$emp_no=$result['emp_number'];
	$total=$result['total'];
	$workdays=25;
	$per_day_salary=$total/$workdays;
	$leave_cnt=mysql_query("select count(id) as cnt from tbl_emp_leave where emp_no='$emp_no' and status='app' and month(fromdate) = '$cmonth'");
	
	//$leave_cnt=mysql_query($em_qry);
	$cnt=mysql_fetch_array($leave_cnt);
	$num_leaves=$cnt['cnt'];
	$leave_cnt11=mysql_query("select count(id) as cnt from tbl_emp_leave where emp_no='$emp_no' and status='pend' and fromdate >= '".date('Y-m-d')."'");
		
	$cnt11=mysql_fetch_array($leave_cnt11);
	$num_leaves11=$cnt11['cnt'];
	
	if($num_leaves == 0)
	{
	$sal_to_paid=$total;
	}	
	else
	{
	$sal=$per_day_salary * $num_leaves;
	$sal_to_paid=$total-$sal;
	}
	$adDate=$result['Adddate'];
	$adDate=explode("-",$adDate);
	$ttrip_status1=$result['trip_status'];
	if($ttrip_status1==0){
	$imgstat='<img src="images/bullat_red.gif" width="21" height="21" border="0" title="Not Active"/>';
	}
	else
	$imgstat='<img src="images/bullat_green.gif" width="21" height="21" border="0" title="Active"/>';
?>
  <tr>
      <td class="tr_td"><a style="cursor:hand;cursor:pointer;" onclick="emp_view('<?php echo $result['emp_number'];?>','<?=$c?>','<?=$total_pages['cn']?>')"><?php echo $result['emp_number'];?></a></td>
      <td class="tr_td"><a style="cursor:hand;cursor:pointer;" onclick="emp_view('<?php echo $result['emp_number'];?>','<?=$c?>','<?=$total_pages['cn']?>')"><?php echo $result['name'];?></a></td>
      <!-- <td class="tr_td"><?php// echo $result['department'];?></td>
      <td class="tr_td"><?php// echo $result['address'];?></td>
      <td class="tr_td"><?php// echo $result['phone_number'];?></td> -->
      <td class="tr_td"><input type="text" value="<?php echo $result['basic_salary'];?>" name="emp_sal" id="emp_sal<?php echo $c;?>" size="6"  onkeyup="salary_change('<?php echo $c;?>','<?php echo $result['id'];?>','emp_sal','emp_da','emp_ta','others')"/></td>
      <td class="tr_td">
	  <input type="hidden" value="<?php echo $result['da'];?>"  id="emp_oldda<?php echo $c;?>" />
	   <input type="hidden" value="<?php echo $result['ta'];?>"  id="emp_oldta<?php echo $c;?>" />
	   <input type="hidden" value="<?php echo $result['basic_salary'];?>"  id="emp_oldsal<?php echo $c;?>" />
	  <input type="text" value="<?php echo $result['da'];?>" name="emp_da" id="emp_da<?php echo $c;?>" size="6" onkeyup="salary_change('<?php echo $c;?>','<?php echo $result['id'];?>','emp_sal','emp_da','emp_ta','others')"/></td>
      <td class="tr_td"><input type="text" value="<?php echo $result['ta'];?>" name="emp_ta" id="emp_ta<?php echo $c;?>" size="6" onkeyup="salary_change('<?php echo $c;?>','<?php echo $result['id'];?>','emp_sal','emp_da','emp_ta','others')"/></td>
      <td class="tr_td"><input type="text" value="<?php echo $result['others']; ?>" size="6" name="others" id="others<?php echo $c;?>" onkeyup="salary_change('<?php echo $c;?>','<?php echo $result['id'];?>','emp_sal','emp_da','emp_ta','others')"/></td>
      <td class="tr_td"><input type="text" size="6" value="<?php echo $result['work_days']; ?>" name="work_days<?php echo $c;?>" id="work_days<?php echo $c;?>" onkeyup="salary_change('<?php echo $c;?>','<?php echo $result['id'];?>','emp_sal','emp_da','emp_ta','others')"/></td>
      <td class="tr_td" align="center"><?php echo $num_leaves; ?></td>
      <td class="tr_td"><span id="sal_paid<?php echo $c;?>"><?php echo $sal_to_paid; ?></span></td>
      <td  class="tr_td"><?php echo $adDate[2].'-'.$adDate[1].'-'.$adDate[0]; ?></td>
      <td width="4%" class="tr_td"><a href="hr-edit-new-employee.php?emp_id=<?=$emp_id?>&id=<?php echo $result['id']; ?>&emp_no=<?php echo $result['emp_number'];?>&page=<?php echo $_REQUEST['page'];?>"><img src="images/icon2.jpg" width="18" height="18" title="Edit"/></a></td>
      <!--<td class="tr_td_b">&nbsp;<img src="images/icon3.jpg" width="17" height="22" title="Edit"/> </td>
      <td class="tr_td_b">&nbsp;<!--<img src="images/icon4.jpg" width="22" height="20" title="Edit"/> </td>
      <td class="tr_td_b">&nbsp;<!--<input type="image" name="Edit" src="images/icon5.jpg" width="20" height="20" title="Edit"/> </td>-->
      <td width="4%" class="tr_td" ><a href="hr-emp-list.php?del=delete&id=<?php echo $result['id']; ?>&emp_no=<?php echo $result['emp_number'];?>&page=<?php echo $_REQUEST['page'];?>" onclick="return confirm('Do you really want to delete this field?');"><img src="images/icon1.jpg" width="21" height="21" title="Delete"/></a></td>
	   <td width="4%" class="tr_td_r" ><a href="hr-emp-list.php?del=active&stid=<?php echo $result['id']; ?>&emp_no=<?php echo $result['emp_number'];?>&page=<?php echo $page;?>" onclick="return confirm('Do you really want to change the status of this field?');"><?=$imgstat?></a></td>

	   <td width="6%" class="tr_td">
	   <input type="hidden" name="serch_id" value="<?php echo $result['id']; ?>"/>
	   <input type="hidden" name="serch_empno" value="<?php echo $result['emp_number']; ?>"/>
	    <input type="hidden" name="serch_page" value="<?php echo $_REQUEST['page'];?>"/>
	   <a style="cusor:hand;cursor:pointer;" onclick="javascript:document.frm_emplist.action='emp-leave-view.php?flag=app&emp=<?php echo $result['emp_number']; ?>';document.frm_emplist.submit();"><font color="#000000">Leaves</font></a>	   </td>
	   	   <td width="8%" class="tr_td">
	    <a style="cusor:hand;cursor:pointer;" onclick="javascript:document.frm_emplist.action='emp-leave-view.php?flag=pend&emp=<?php echo $result['emp_number']; ?>';document.frm_emplist.submit();" class="tr_link"><font color="#000000">Leave Requests(<?=$dcnt?>)</font></a></td>

	   <td width="7%" class="tr_td">
	    <a style="cusor:hand;cursor:pointer;" onclick="javascript:document.frm_emplist.action='emp-leave-view.php?flag=notapp&emp=<?php echo $result['emp_number']; ?>';document.frm_emplist.submit();" class="tr_link"><font color="#000000">Rejected Leaves</font></a></td>
    <td width="13%" class="tr_td" style="border-right:1px solid #6b6b6b; "><a href="emp-leave-req.php?ed_id=<?php echo $result['emp_number']; ?>" class="tr_link"><font color="#000000">Apply Leave</font></a> </td>
    </tr>
	<tr><td  colspan="16" class="tr_td_btm" style="border-right:1px #6b6b6b solid"><span id="empdetls<?=$c?>"></span></span></td></tr>
<?php
$c++;
}
}else{
?>
 <tr>
      <td class="tr_td_no" colspan="17">No Records Found!!</td></tr>
<?
}
?></table></div>
 <div align="right" style="padding-top:10px;"><?=$pagination?></div>
