Location: PHPKode > projects > E-hris > staffturnoverrpt.php
<?
session_start();
/*
   * e-hris (Electronic-Human Resource Information System v 1.3.0 Alpha) Is an open source human resource information management system
   * developed to automate all aspects of human resource management, with the dual benefits of reducing the workload of the HR department as well as increasing the efficiency of the department by standardising
   * HR processes for any organization from small-enterprises to large scale organizations.
   * Copyright (C) 2008  David Muturi

   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.

   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.

   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
?>
<!DOCTYPE html
	PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="description" content="Electronic Human Resource Information Management System">


    <link rel="stylesheet" href="js/example.css" TYPE="text/css" MEDIA="screen">
	<link rel="stylesheet" type="text/css" href="css/employees.css" />
	<link rel="stylesheet" type="text/css" href="css/main.css"/>
    <link href="css/text.css" rel="stylesheet" type="text/css"/>
	<title>E-hris Electronic Human Resource information system</title>
<style type="text/css">
<!--
.copysmall {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #3B3B3B; font-size: 12px; margin-top:3px; margin-bottom:11px; margin-left:0px; margin-right:0px }
.copy {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #3B3B3B; font-size: 13px; margin-top:3px; margin-bottom:11px; margin-left:0px; margin-right:0px }
.copymed {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #3B3B3B; font-size: 14px; margin-top:3px; margin-bottom:11px; margin-left:0px; margin-right:0px }
.copylarge {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #3B3B3B; font-size: 15px; margin-top:3px; margin-bottom:11px; margin-left:0px; margin-right:0px }
.copymedred {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #FF0000; font-size: 14px; margin-top:3px; margin-bottom:11px; margin-left:0px; margin-right:0px }
.copyheader {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #2778CB; font-size: 14px; margin-top:3px; margin-bottom:0px; margin-left:0px; margin-right:0px }
.copyheaderwhite {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #FFFFFF; font-size: 14px; margin-top:3px; margin-bottom:0px; margin-left:0px; margin-right:0px }
.header7, h7 {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #2778CB; font-size: 15px; font-weight: bold }
.copysmalltitle {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #2778CB; font-size: 15px; font-weight: bold }
.copysubtitle {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #2778CB; font-size: 15px }
.copyfooter {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #000000; font-size: 13px }
.copydownload {  font-family: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif; color: #3B3B3B; font-size: 13px }
.info   { color: black; background-color: transparent; font-weight: normal; }
  .warn   { color: rgb(120,0,0); background-color: transparent; font-weight: normal; }
  .error  { color: red; background-color: transparent; font-weight: bold }
-->
</style>

 <link rel="stylesheet" type="text/css" href="css/epoch_styles.css"/>
 <link rel="stylesheet" type="text/css" href="ajaxtabs/ajaxtabs.css" />
 
 <script type="text/javascript" src="css/epoch_classes.js"></script>
 <script type="text/javascript" src="js/formval.js"></script> 
 <script language="JavaScript" src="js/calendar1.js"></script>
<script type="text/javascript" src="js/tabber.js">
</script>
<style type="text/css">
<!--
.style5 {font-size: 14px}
.style6 {color: #000000}
.style7 {color: #FFFFFF}
-->
</style>
 <link rel="stylesheet" type="text/css" href="css/epoch_styles.css"/>
 <link rel="stylesheet" type="text/css" href="css/jqueryslidemenu.css" />
 <link rel="stylesheet" type="text/css" href="ajaxtabs/ajaxtabs.css" />


<!--[if lte IE 7]>
<style type="text/css">
html .jqueryslidemenu{height: 1%;} /*Holly Hack for IE7 and below*/
</style>
<![endif]-->
<script language="JavaScript" src="js/highlight.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jqueryslidemenu.js"></script>
<script type="text/Javascript">

/*You can also place this code in a separate file and link to it like epoch_classes.js*/
	var dp1_cal,dp2_cal
     window.onload = function () {
	
	dp1_cal  = new Epoch('epoch_popup','popup',document.getElementById('datefrom'));
	dp2_cal = new Epoch('epoch_popup','popup',document.getElementById('dateto'));
};

 function validateOnSubmit() {
	var elem;
    var errs=0;
	// execute all element validations in reverse order, so focus gets
    // set to the first one in error.
	
	if (!validatePresent(document.forms.addbankfrm.bank,'inf_bank'))  errs += 1; 
		    
	if (errs>1)  alert('There are fields which need correction before submitting');
    if (errs==1) alert('There is a field which needs correction before submitting');
	
  return (errs==0);
 }
 
 </script>
 </head>
<body bgcolor="#FFFFFF">
<? 
  include "includes/config.php";
	
  if (empty($_SESSION["username"]))
    die("<meta http-equiv='refresh' content='1;url=login.php'>");

  
  include "includes/functions.php";

  require_once "includes/db.php";
  
  $d = new dbC();
  $d->connect($db_host, $db_user, $db_pass, $db); 
  
  $username = $_SESSION["username"];
  $sqlstr="select * from hrusers  where username like '%".$username."%'";
  $data=$d->query($sqlstr);
  $row=$d->fetch_object($data);
  $fullname=$row->name; 
  
  $userid=$row->id; createmenu($empid,$username,$d); 
 //fetch departments,sections
   $sqlstr="select distinct dept, station from prmember order by dept,station";
   
   if (!empty($_POST["datefrom"]) && !empty($_POST["dateto"]))
   {
      $dispmsg = "<b>Employees Employed/Terminated between ".$_POST["datefrom"]." and ".$_POST["dateto"]."</b>";
	   
      $datefrom=dateconvert($_POST["datefrom"],1);
	  $dateto=dateconvert($_POST["dateto"],1);
			 
	 
		     
	  
	}
	
	 
		  
	if (!empty($dispmsg))
	  echo "$dispmsg";	
	else
	 echo"<b>Employees Employed/Terminated during the last one year from today</b>";  
		 

 ?> 
 
<br><br>

	<form name="form1" method="post" action="staffturnoverrpt.php">
	
	<table width="100%"  border="0">
      <tr bgcolor="F0F0F0">
        <td width="15%"><div align="right">Employment Date From</div></td>
        <td width="22%"><span class="highlight">
          <input name="datefrom" type="text" id="datefrom"  <? if (!empty($dob)) echo "value=$dob"; ?>>
        </span>
        </td>
        <td width="15%"><div align="right">Employment Date To </div></td>
        <td width="24%"><input name="dateto" type="text" id="dateto"  <? if (!empty($dob)) echo "value=$dob"; ?>></td>
        <td width="12%"><input name="Search" type="submit" id="Search" <?  if (!empty($_POST["searchval"])) echo "value=\"Show All\""; else echo "value=\"Search\""; ?>></td>
      </tr>
    </table> 
	</form>  
	<?
	  if (!empty($contexpmsg))
	    echo $contexpmsg."<br>";
	  
	  if (!empty($retmsg))
	    echo $retmsg."<br>";
	  
	?>  
      <h1>&nbsp;</h1>
   </td>
  </tr>
  <tr><td>
   <table width="100%"  border="0">
   <tr>
       
        <th width="2%">Department</th>
		<th width="2%">DeptCode</th>
		<th width="2%">Section Code</th>
		<th width="5%"><div align="center">No. of Staff Employed </div></th>
		<th width="5%"><div align="center">No. of Staff Who have Left </div></th>
        </tr>
	  <?
	    	
		 //count active staff for now	
		
		 
		  $result=$d->query($sqlstr) or die(mysql_error());
				
		  while ($row=$d->fetch_object($result))
		  {
		  
		  //total employed
		   if (!empty($datefrom) && !empty($dateto)){
		    $querystr ="select count(memberno) as totalemp,DeptCode,DeptName,StationCode,StationName from prmember left join prdept on Dept=DeptCode
             left join prstn on StationCode=Station
             where DeptCode='$row->dept' and StationCode='$row->station' and empdate >= '$datefrom' and empdate <= '$dateto' and empstatus_fk =1 group by Deptcode,deptname,StationCode,StationName ";
		   }else
		      $querystr=" select count(memberno) as totalemp,DeptCode,DeptName,StationCode,StationName from prmember  left join prdept on Dept=DeptCode
              left join prstn on StationCode=Station where DeptCode='$row->dept' and StationCode='$row->station' and empdate >=date_sub(curdate(),interval 365 day) and empdate <=curdate()
             and empstatus_fk =1 group by Deptcode,deptname,StationCode,StationName";
	      
		 
			
			$queryresult=$d->query($querystr) or die(mysql_error());
		    $data=$d->fetch_object($queryresult);
		   
		   //total quit
		 
		   if (!empty($datefrom) && !empty($dateto)){
		     $querystr= "select count(memberno) as totalquit,DeptCode,DeptName,StationCode,StationName from prmember left join prdept on Dept=DeptCode
           left join prstn on StationCode=Station where quitdate >='$datefrom' and quitdate <='$dateto'
           and empstatus_fk <>1 and DeptCode='$row->dept' and StationCode='$row->station' group by Deptcode,deptname,StationCode,StationName";
		   
		   }
		   else
		   $querystr= "select count(memberno) as totalquit,DeptCode,DeptName,StationCode,StationName from prmember left join prdept on Dept=DeptCode
           left join prstn on StationCode=Station where quitdate >=date_sub(curdate(),interval 365 day) and quitdate <=curdate()
           and empstatus_fk <>1 and DeptCode='$row->dept' and StationCode='$row->station' group by Deptcode,deptname,StationCode,StationName";
		  
		   $qresult=$d->query($querystr) or die(mysql_error());
		   $qdata=$d->fetch_object($qresult);
		 
		    echo "<tr>";
			if (!empty($data->DeptName))
			  echo "<td>".$row->dept."&nbsp;</td>";
		    else
			  echo "<td>".$row->dept."&nbsp;</td>";
			
			echo "<td>".$row->dept."&nbsp;</td>";  
			echo "<td>".$row->station."&nbsp;</td>"; 
			
			if (!empty($data->totalemp))
			  echo "<td><a href=\"javascript:viewdetail('$row->dept','$row->station',2)\">".$data->totalemp."</a>&nbsp;</td>";
			else
			  echo "<td>0&nbsp;</td>";
			
			if (!empty($qdata->totalquit))   
		      echo "<td><a href=\"javascript:viewdetail('$row->dept','$row->station',1)\">".$qdata->totalquit."</a>&nbsp;</td>";
		    else
			  echo "<td>0&nbsp;</td>";
			  
			$totalemp=$data->totalemp+$totalemp;
			$totalquit=$qdata->totalquit+$totalquit;
		    echo "</td></tr>";
		  
		  }
	     echo "<td> <b>Totals</b> </td><td>&nbsp;</td><td>&nbsp;</td>";
		 echo "<td> <b>$totalemp</b> </td><td> <b>$totalquit</b> </td>";
	  ?>
   </table>
	</td></tr>  
    </table>


<?
  $d->close();
  footer();
?>
<script language="javascript">
  function viewdetail(param1,param2,param3)
	 {
        var url = "staffturnoverrptdet.php?dept="+param1+"&stn="+param2+"&quit="+param3;
   
        newwin = window.open(url,'View','width=900,height=600,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollbars=3');
        newwin.focus();
     }
</script>
<script language="javascript">
  function ChangePass()
	 {
        var url = "changepass.php";
   
        newwin = window.open(url,'View','width=500,height=400,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollbars=3');
        newwin.focus();
     }
</script>
</body>

</html>



Return current item: E-hris