<?php
$PageSecurity = 2;
include('includes/SQL_CommonFunctions.inc');
$title = _('Process/View Pay Chart') ;
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];echo "<br>";

$currentyear=date('Y');
$currentmonth=date('m');
?>
<h2 align="center"><strong>Pay Chart</strong></h2>
<?php 
if($_REQUEST['Proceed']!='' && $_REQUEST['view']=='1')
{
	$filter=array();
	
	$month=$_REQUEST['month'];
	$year=$_REQUEST['year'];
	$grade=$_REQUEST['grade'];
	$site=$_REQUEST['site'];
	$designation=$_REQUEST['designation'];
	$department=$_REQUEST['department'];
	$employee=$_REQUEST['employee'];
	$shift=$_REQUEST['shift'];
	$status=$_REQUEST['status'];
	
	if($month!='')
	$filter[]="A.month='".$month."'";
	if($year!='')
	$filter[]="A.year='".$year."'";
	if($grade!='000')
	$filter[]="B.grade='".$grade."'";
	if($site!='000')
	$filter[]="B.emp_site='".$site."'";
	if($designation!='000')
	$filter[]="B.designation='".$designation."'";
	if($department!='000')
	$filter[]="B.department='".$department."'";
	if($employee!='000')
	$filter[]="B.id='".$employee."'";
	
	if(isset($filter)){
	if(count($filter)>0)
	{
		$filter1=implode(" and ",$filter);
	}	
	$sql="Select A.*, B.* from pay_chart_master A, empmaster B where A.emp_id=B.id and $filter1";
	}
	//echo $sql;
	else
	if($_REQUEST['status']=='All')
	{
		$sql="Select A.*, B.* from pay_chart_master A, empmaster B where A.emp_id=B.id";
	}
	
	 
$result=DB_query($sql,$db);
}
?>
<form action="index.php?route=process_pay_chart&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&view=1" method="post">
<table width="60%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th><strong>MONTH</strong></th>
    <td><select name="month" id="month" style="width:75px">
	<option value="01" <?php echo($currentmonth=='01'?'selected':'')?>>January</option>
	<option value="02" <?php echo($currentmonth=='02'?'selected':'')?>>February</option>
	<option value="03" <?php echo($currentmonth=='03'?'selected':'')?>>March</option>
	<option value="04" <?php echo($currentmonth=='04'?'selected':'')?>>April</option>
	<option value="05" <?php echo($currentmonth=='05'?'selected':'')?>>May</option>
	<option value="06" <?php echo($currentmonth=='06'?'selected':'')?>>June</option>
	<option value="07" <?php echo($currentmonth=='07'?'selected':'')?>>July</option>
	<option value="08" <?php echo($currentmonth=='08'?'selected':'')?>>August</option>
	<option value="09" <?php echo($currentmonth=='09'?'selected':'')?>>September</option>
	<option value="10" <?php echo($currentmonth=='10'?'selected':'')?>>October</option>
	<option value="11" <?php echo($currentmonth=='11'?'selected':'')?>>November</option>
	<option value="12" <?php echo($currentmonth=='12'?'selected':'')?>>December</option>
	</select>
	</td>
    <th><strong>YEAR</strong></th>
    <td>
	<select name="year" id="year" style="width:50px">
	<?php 
	for($year=date('Y')+9;$year>1999;$year--){
	?>
	<option value="<?php echo $year;?>"<?php echo ($currentyear==$year?'selected':'')?>><?php echo $year;?></option>
<?php }	?>
	</select>
	</td>
    <th><strong>GRADE</strong></th>
    <td><select name="grade" id="grade">
      <option value="000">Select</option>
	  <?php 
	  $g_sql=DB_query("Select * from emp_grade",$db);
	  while($g_row=DB_fetch_array($g_sql))
	  {
	  ?>
	  <option value="<?php echo $g_row['id'];?>"><?php echo $g_row['grade_name'];?></option>
	  <?php } ?>
    </select></td>
  </tr>
  <tr>
    <th><strong>SITE</strong></th>
    <td colspan="3">
	<select name="site" id="site">
	<option value="000">Select</option>
	  <?php
	  if($_SESSION['AssignedBranch']!=''){ 
	  $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);}
	  else
	  {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
	  while($site_row=DB_fetch_array($site_sql))
	  {
	  ?>
	  <option value="<?php echo $site_row['loccode'];?>"><?php echo $site_row['locationname'];?></option>
	  <?php } ?>
	</select>
	</td>
    <th><strong>DESIGNATION</strong></th>
    <td><select name="designation" id="designation">
     <option value="000">Select</option>
	  <?php 
	  $desig_sql=DB_query("select * from desigmaster",$db);
	  while($desig_row=DB_fetch_array($desig_sql))
	  {
	  ?>
	  <option value="<?php echo $desig_row['desigcode'];?>"><?php echo $desig_row['designame'];?></option>
	  <?php } ?>
    </select></td>
  </tr>
  <tr>
    <th><strong>DEPARTMENT</strong></th>
    <td colspan="3"><select name="department" id="department">
     <option value="000">Select</option>
	  <?php 
	  $dept_sql=DB_query("select * from deptmaster",$db);
	  while($dept_row=DB_fetch_array($dept_sql))
	  {
	  ?>
	  <option value="<?php echo $dept_row['deptcode'];?>"><?php echo $dept_row['deptname'];?></option>
	  <?php } ?>
    </select></td>
    <th><strong>EMPLOYEE</strong></th>
    <td><select name="employee" id="employee">
      <option value="000">Select</option>
	  <?php 
	  $emp_sql=DB_query("Select id,emp_name from empmaster",$db);
	  while($emp_row=DB_fetch_array($emp_sql))
	  {
	  ?>
	  <option value="<?php echo $emp_row['id'];?>"><?php echo $emp_row['emp_name'];?></option>
	  <?php } ?>
    </select></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="3">&nbsp;</td>
    <th><strong>STATUS</strong></th>
    <td><select name="status" id="status">
      <option value="000">Select</option>
	  <option value="All">All Employees</option>
    </select></td>
  </tr>
</table>
<br>
<p align="center">
<input type="submit" name="Proceed" value="Proceed">
<input type="submit" name="Save" value="Save">
</p>
</form>
<br />
<form action="" method="post">
<div align="center">
<div style="overflow:auto;width:800px;height:200px">
<!--<p align="right"><input type="submit" name="Edit" value="Edit Record" /></p>-->
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <th><strong>EMPLOYEE</strong></th>
    <th><strong>DATE OF </strong></th>
    <th><strong>EMPLOYEE</strong></th>
    <th>&nbsp;</th>
	<th>&nbsp;</th>
    <th>&nbsp;</th>
    <th><strong>ENTITLED</strong></th>
    <th><strong>PAID</strong></th>
    <th>&nbsp;</th>
	<th>&nbsp;</th>
    <th><strong>TOTAL</strong></th>
    <th><strong>DEDUCTIONS</strong></th>
	<th>&nbsp;</th>
    <th><strong>NET</strong></th>
	<th><strong>TOTAL</strong></th>
	<th><strong>REMAINING</strong></th>
    <th><strong>SIGN/</strong></th>
  </tr>
  <tr>
    <th><strong>CODE</strong></th>
    <th><strong>JOINING</strong></th>
    <th><strong>NAME</strong></th>
    <th><strong>SITE</strong></th>
	<th><strong>DEPARTMENT</strong></th>
    <th><strong>DESIGNATION</strong></th>
    <th><strong>SALARY</strong></th>
    <th><strong>DAYS(P)</strong></th>
	<th><strong>LEAVES(A)</strong></th>
    <th><strong>EARNINGS</strong></th>
    <th><strong>EARNINGS</strong></th>
    <th><strong>ADVANCE</strong></th>
    <th><strong>TOTAL</strong></th>
    <th><strong>SALARY</strong></th>
	<th><strong>LEAVES</strong></th>
	<th><strong>LEAVES</strong></th>
    <th><strong>REMARKS</strong></th>
  </tr>
  <?php 
  if($_REQUEST['Proceed']!='' && $_REQUEST['view']=='1')
{
 if(DB_num_rows($result)>0)
 { 
 $i=1;
  while($myrow=DB_fetch_array($result))
  {
  ?>
  <tr bgcolor="#B8CBCB">
    <td><?php echo $myrow['emp_code'];?></td>
    <td><?php echo ConvertSQLDate($myrow['doj']);?></td>
    <td><?php echo $myrow['emp_name'];?></td>
    <td><?php 
	$site_sql=DB_query("Select locationname from locations where loccode='".$myrow['emp_site']."'",$db);
	$site_result=DB_fetch_array($site_sql);
	echo $site_result['locationname'];?></td>
	<td><?php 
	$dept_sql=DB_query("Select deptname from deptmaster where deptcode='".$myrow['department']."'",$db);
	$dept_result=DB_fetch_array($dept_sql);
	echo $dept_result['deptname'];?></td>
    <td><?php 
	$desig_sql=DB_query("Select designame from desigmaster where desigcode='".$myrow['designation']."'",$db);
	$desig_result=DB_fetch_array($desig_sql);
	echo $desig_result['designame'];?></td>  
    <td><input type="text" name="salary[<?php echo $i;?>]" id="salary_<?php echo $i;?>" value="<?php echo $myrow['salary'];?>" size="10" readonly="true" /></td>
    <td><input type="text" name="no_of_days[<?php echo $i;?>]" id="no_of_days_<?php echo $i;?>" value="<?php echo $myrow['no_of_days'];?>" size="3" readonly="true"/></td>
	<td><input name="leaves[<?php echo $i;?>]" type="text" id="leaves_<?php echo $i;?>" value="<?php echo $myrow['leaves'];?>" size="5" readonly="true"/></td>
    <td><input type="text" name="earnings[<?php echo $i;?>]" id="earnings_<?php echo $i;?>" value="<?php echo $myrow['earnings'];?>" size="10" readonly="true"/></td>
    <td><input name="tot_earning[<?php echo $i;?>]" type="text" id="tot_earning_<?php echo $i;?>" value="<?php echo $myrow['tot_earning'];?>" size="10" readonly="true"/></td>
    <td><input type="text" name="advance[<?php echo $i;?>]" id="advance_<?php echo $i;?>" value="<?php echo $myrow['advance'];?>" size="10" /></td>
    <td><input type="text" name="final_total[<?php echo $i;?>]" id="final_total_<?php echo $i;?>" value="<?php echo $myrow['final_total'];?>" size="10" readonly="true"/></td>
    <td><input name="net_salary[<?php echo $i;?>]" type="text" id="net_salary_<?php echo $i;?>" value="<?php echo $myrow['net_salary'];?>" size="10" readonly="true"/></td>
	<td><input name="tot_leaves[<?php echo $i;?>]" type="text" id="tot_leaves_<?php echo $i;?>" value="<?php echo $myrow['tot_leaves'];?>" size="10" readonly="true"/></td>
	<td><input name="remain_leaves[<?php echo $i;?>]" type="text" id="remain_leaves_<?php echo $i;?>" value="<?php echo $myrow['remain_leaves'];?>" size="10" readonly="true"/></td>
    <td><input type="text" name="sign_remarks[<?php echo $i;?>]" id="sign_remarks_<?php echo $i;?>" value="<?php echo $myrow['sign_remarks'];?>" size="20" /></td>
  </tr>
  <?php $i++;} 
 }
 else
 {?>
 <tr>
 <td colspan="14"><h3 align="center"><strong><font color="#FF0000">No Record Found!</font></strong></h3></td>
 </tr>
<?php  	
 } 
}?>
</table>              
<input type="hidden" name="ctr" id="ctr" value="<?php echo $i;?>" />
</div>
</div>
</form>
<?php
include('includes/footer.inc');
?>