<script>
function validate_branch()
{
	$branch = $('#site').val();
	if($branch == "")
	{
		alert("Select Branch");
		return false;
	}
	return true;
}

function getsubcategory(str)
{
	if (str.length==0)
	{
	document.getElementById("groupwise").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("SUBGRP").innerHTML=data[0]
	document.getElementById("itemid").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","GetSubGrpPR.php?GroupId="+str,true);
	xmlhttp.send();
}
function GetItemForPr(str)
{
	if (str.length==0)
	{
	document.getElementById("subgroupwise").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("itemid").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","GetPRItems.php?SubGroupId="+str,true);
	xmlhttp.send();
}
function showIndent(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	//var data=xmlhttp.responseText.split("__");	
	//alert(data);
	//document.getElementById("vender").innerHTML= xmlhttp.responseText;
        document.getElementById("UserIndent").innerHTML=xmlhttp.responseText;
        displayCode(str);    	
    }
  }
xmlhttp.open("GET","check_data_fin.php?section=IndentUser&site="+str,true);
xmlhttp.send();
}	

function displayCode(str)
{
	$.post('getCode.php',{'str':str},function(data){
		$('#project').html(data);
	});
}
function changeArea(str)
{
	$.post('getCode.php',{'str':str,'changeArea':'yes'},function(data){
		$('#area').html(data);
	});
}

function showEmpDeptWise(str)
{
	$.post('getCode.php',{'str':str,'changeEmp':'yes'},function(data){
			$('#requition_by').html(data);
		});		
}
</script>

<?php
error_reporting(0);
$maxAssign="select max(no_of_assignee) as numMax from conf_purch_approval where company_id='".$_SESSION['ACGCompanyId']."' and doc_type='PR'";
$maxAssignExec=DB_query($maxAssign,$db);
$maxAssignDATA=DB_fetch_array($maxAssignExec);
$maximAss=$maxAssignDATA['numMax'];
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php  echo  $page_title; include('POModule/Class-ItemMaster.php');?></h1>
<form action="" method="post">
<table width="100%" align="center" class="" border="0" cellspacing="0" cellpadding="3">
	<tr class="row1">
	<td width="13%"><strong>Branch</strong></td>
	<?php 
	$ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')";
	$site_sql=DB_query($ss1,$db);
	?>
	<td width="20%">
	<select name="site" id="site" style="width:98%;" onchange="showIndent(this.value)">
	<option value="">Select</option>
	<?php 
	
	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 width="13%"><strong>Employee</strong></td>
	<td width="20%"><select name="employee" id="employee" style="width:98%;">  
	           <option value=""> ----Select -----</option>
                <?php $emp="select * from empmaster";
                  $empRes=DB_query($emp,$db); 
                  while($empRow=DB_fetch_array($empRes)){?>?>
                  <option value="<?php echo $empRow['id'];?>" <?php if($_REQUEST['employee']==$empRow['id']) { ?> selected <?php } ?>><?php  echo $empRow['emp_name']; ?></option>
                <?php } ?>
          </select></td>
      <td width="13%"><strong>Adjustment Type</strong></td>
	<td><select name="adjustmet_type" id="adjustmet_type" style="width:98%;">  
	           <option value="0">Select</option>
                <?php $emp1="select * from other_deduction_master where type='D'";
                  $empRes1=DB_query($emp1,$db); 
                  while($empRow1=DB_fetch_array($empRes1)){?>
                  <option value="<?php echo $empRow1['id'];?>" <?php if($_REQUEST['adjustmet_type']==$empRow1['id']) { ?> selected <?php } ?>  ><?php  echo $empRow1['name']; ?></option>
                <?php } ?>
          </select></td>   	
</tr>
<tr class="row1">
	<td><strong>Month :</strong></td>
    <td><select name="paymonth" id="paymonth" style="width:98%;" onchange="chk_type_employee();">
 		<?php	$arr=array("01"=>"Jan","02"=>"Feb","03"=>"Mar","04"=>"Apr","05"=>"May","06"=>"June","07"=>"July","08"=>"Aug","09"=>"Sept","10"=>"Oct","11"=>"Nov","12"=>"Dec");
 				foreach ($arr as $key => $value) {
 				$p='';
 				if( $key==$_REQUEST['paymonth'])
				$p='selected';?>
			<option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 		<?php } ?>
		</select></td>
    <td><strong>Year :</strong></td>
    <td><select name="payyear" id="payyear"  style="width:98%;" onchange="chk_type_employee();">
 		<?php for($i=date('Y');$i>2000;$i--){
 			  $p='';
 	          if( $i==$_REQUEST['payyear'])
	          $p='selected';?>
			<option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
 		<?php }?>
		</select></td>
		<td colspan="2"></td>
</tr>
	<tr class="row1">
		<td style="text-align:center;" colspan="6"><input type="submit" name="SearchBranch" value="Search" class="search" style="cursor:pointer;" onclick="return validate_branch();"></td>
	</tr>
</table>
</form>

<?php if($_REQUEST['SearchBranch']){
$filter=array();
$months=array("1"=>"Jan","2"=>"Feb","3"=>"Mar","4"=>"Apr","5"=>"May","6"=>"Jun","7"=>"Jul","8"=>"Aug","9"=>"Sep","10"=>"Oct","11"=>"Nov","12"=>"Dec");
    
		 
	if($_REQUEST['site']!='' ) 
	 {
		 $filter[]="A.site='".$_REQUEST['site']."' ";
	 }
	
	 if($_REQUEST['employee']!='' ) 
	 {
		 $filter[]="A.empid='".$_REQUEST['employee']."' ";
	 }

	 if($_REQUEST['adjustmet_type']!='0' ) 
	 {
		 $filter[]="B.other_ded='".$_REQUEST['adjustmet_type']."' ";
	 }
	  if($_REQUEST['paymonth']!='' ) 
	 {
		 $filter[]="A.month='".$_REQUEST['paymonth']."' ";
	 }
	  if($_REQUEST['payyear']!='' ) 
	 {
		 $filter[]="A.year='".$_REQUEST['payyear']."' ";
	 }
	 
	 if(!empty($filter))
	 $filter1=implode(" and ",$filter);
	 else
	 $filter1="1=1";	
   
          $sql2 = "select sum(B.amount) as amt ,A.empid as empid ,A.month as month,A.year as year from monthly_other_deducation A inner join monthly_other_deducation_details B
         on A.id=B.parentid  where $filter1 group by A.empid ";
 } ?>


<?php if($_REQUEST['SearchBranch']){ ?>
<div id="pr">
<p align="right"><a href="monthly_other_adjusment_report.php" target="_blank" class="search">Print</a></p>

<div align="center" style="font-size:12px;"><strong><?php echo $message; ?></strong> </div>
<br />
<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:solid 1px #808080;">
  <tr>
    <th width="3%" style="text-align:left;"><strong>S. No.</strong></th> 
    <th width="10%" style="text-align:left;"><strong>Employee code</strong></th>
    <th style="text-align:left;"><strong>Employee Name</strong></th>
	<th width="10%" style="text-align:left;"><strong>Month</strong></th>
	<th width="8%" style="text-align:left;"><strong>Year</strong></th>
	<th width="8%" style="text-align:left;"><strong>Amount</strong></th>    
  </tr>
  <?php

    $i=1;
	$res = DB_query($sql2,$db);
	if(DB_num_rows($res)>0) {
 	while($row = DB_fetch_array($res))
	{
		
	 ?>
	  <tr bgcolor="#FFFFFF" onmouseover="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onmouseout="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
    	<td><?php echo $i++;?></td>
    	<td><?php echo $empname =$s->getField('empmaster','id',$row['empid'],'emp_code');?></td>
    	<td><?php echo $empcode=$s->getField('empmaster','id',$row['empid'],'emp_name'); ?></td>
		<td><?php echo $monthdata=$months[$row['month']];?></td>
		<td><?php echo $row['year'];?></td>
		<td style="text-align:right;"><?php  echo $row['amt'];?></td>		     
   </tr>
    <?php $i++;
    $data[]=array("empcode"=>$empcode,"empname"=>$empname,"month"=>$monthdata,"year"=>$row['year'],"amt"=>$row['amt']);
     } 
$_SESSION['monthly_adjustment']=$data;
 } else { ?>
    <tr><td colspan="6">No Records</td></tr>
    <?php
unset($_SESSION['monthly_adjustment']);
     } ?>
        
</table>
</div>
<?php  } ?>

</div>
</div>

