<style type="text/css">
ul.pagination {
	font-family: "Arial", "Helvetica", sans-serif;
	font-size: 13px;
	height: 100%;
	list-style-type: none;
	margin: 20px 0;
	overflow: hidden;
	padding: 0;
}
ul.pagination li.details {
	background-color: white;
	border-color: #C8D5E0;
	border-image: none;
	border-style: solid;
	border-width: 1px 1px 2px;
	color: #1E598E;
	font-weight: bold;
	padding: 8px 10px;
	text-decoration: none;
}
ul.pagination li.dot {
	padding: 3px 0;
}
ul.pagination li {
	float: left;
	list-style-type: none;
	margin: 0 3px 0 0;
}
ul.pagination li:first-child {
	margin-left: 0;
}
ul.pagination li a {
	color: black;
	display: block;
	padding: 7px 10px;
	text-decoration: none;
}
ul.pagination li a img {
	border: medium none;
}
ul.pagination li a.current {
	background-color: white;
	border-radius: 0 0 0 0;
	color: #333333;
}
ul.pagination li a.current:hover {
	background-color: white;
}
ul.pagination li a:hover {
	background-color: #C8D5E0;
}
ul.pagination li a {
	background-color: #F6F6F6;
	border-color: #C8D5E0;
	border-image: none;
	border-style: solid;
	border-width: 1px 1px 2px;
	color: #1E598E;
	display: block;
	font-weight: bold;
	padding: 8px 10px;
	text-decoration: none;
}
</style>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php 
//unset($_SESSION['employee_code']);
//error_reporting(0);
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$target_rurl="index.php?route=HRModule/LTA_Medical_report&modid=".$modid."&frmid=".$frmid."";
$rurl_view="index.php?route=View_master_payslip&action=View&modid=".$modid."&frmid=".$frmid."";
//if($_REQUEST['paymonth']==date("n") && isset($_REQUEST['Search'])){?>
	<script>//alert("You not process current month salary.");</script>
<?php
	//$s->PageLocation($target_rurl);
//}
/*else*/ 

function floor_dec($number,$precision,$separator)
{
    $numberpart=explode($separator,$number);
    $numberpart[1]=substr_replace($numberpart[1],$separator,$precision,0);
    if($numberpart[0]>=0)
    {$numberpart[1]=floor($numberpart[1]);}
    else
    {$numberpart[1]=ceil($numberpart[1]);}

     $ceil_number= $numberpart[1];
    return $ceil_number;
}
function floor_dec1($number,$precision,$separator)
{
    $numberpart=explode($separator,$number);
    $numberpart[1]=substr_replace($numberpart[1],$separator,$precision,0);
    if($numberpart[0]>=0)
    {$numberpart[1]=floor($numberpart[1]);}
    else
    {$numberpart[1]=ceil($numberpart[1]);}

     $ceil_number= $numberpart[0];
    return $ceil_number;
}


if($_REQUEST['Search'])
{
	$_SESSION['Mstemp_paysal']=array();			 
	$_SESSION['Mstemp']=array();
	$paystatus=true;  
	$_SESSION['payyear']=$_REQUEST['payyear'];
	$_SESSION['paymonth']=$_REQUEST['paymonth'];
	$_SESSION['employee_code']=$_REQUEST['employee_code'];
	$_SESSION['emptype']=$_REQUEST['emptype'];
	$_SESSION['emp_salprocess_site']=$_REQUEST['site'];
	$years=$_SESSION['payyear'];
	$month=$_SESSION['paymonth'];	   
	$employee_code=$_SESSION['employee_code'];
	$emptype=$_SESSION['emptype'];
	$emp_salprocess_site=$_SESSION['emp_salprocess_site'];
}	 

if($_REQUEST['Reset'])
{
	unset($_SESSION['Mstemp_paysal']);			 
	unset($_SESSION['Mstemp']);
	unset($_SESSION['payyear']);
	unset($_SESSION['paymonth']);
	unset($_SESSION['employee_code']);
	unset($_SESSION['emptype']);
	unset($_SESSION['emp_salprocess_site']);
	unset($_SESSION['payyear']);
	unset($_SESSION['paymonth']);	   
	unset($_SESSION['emptype']);
	unset($_SESSION['emp_salprocess_site']);
	$s->PageLocation($target_rurl);
}	
?>
<form action="" method="post">
<h1>LTA &amp; Medical Report</h1>

<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="13%" align="right">Site</td>
    <td width="20%"><select name="site" id="site" >
			<option value="000">---ALL---</option>
			<?php $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
			while($site_row=DB_fetch_array($site_sql)){?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['emp_salprocess_site']==$site_row['loccode']?'selected':'');?>><?php echo $site_row['locationname'];?></option>
			<?php } ?>
		</select></td>
    <td width="13%" align="right">Employee Type</td>
    <td width="20%"><select name="emptype" id="emptype" onchange="ShowDiv(this.value,'hid-empdiv','GetEmployee.php?site='+document.getElementById('site').value)" > 
			<option value="0" >---</option>
			<option value="Permanent" <?php echo($_SESSION['emptype']=='Permanent'?'selected':'')?>>Permanent</option>
			<option value="Temporary" <?php echo($_SESSION['emptype']=='Temporary'?'selected':'')?>>Temporary</option>
		</select></td>
    <td width="13%" align="right">Employee Code</td>
    <td><div id='hid-empdiv'><select name="employee_code" id="employee_code" >
			<option value="All">All</option>
			<?php $emp_sql=DB_query("Select id, emp_code,emp_name from empmaster order by emp_name",$db);
			while($emp_row=DB_fetch_array($emp_sql)){?>
			<option value="<?php echo $emp_row['id'];?>"<?php if($_SESSION['employee_code']==$emp_row['id'])echo "selected";?>><?php echo $emp_row['emp_name'].' ( '.$emp_row['emp_code'].' ) ' ;?></option>
			<?php }?>
		</select></div></td>
  </tr>
  <tr class="row1">
  	<td align="right">Month</td>
    <td><select name="paymonth" id="paymonth"  >
 		<?php	$arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
 				foreach ($arr as $key => $value) {
 				$p='';
 				if( $key==$_SESSION['paymonth'])
				$p='selected';?>
			<option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 		<?php } ?>
		</select></td>
    <td align="right">Year</td>
    <td align="left" valign="top"><select name="payyear" id="payyear" >
 		<?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">&nbsp;</td>
  </tr>
  <tr class="row1">
    <td colspan="6" align="center"><input type="submit" name="Search" class="search" value="Search" onclick="return chksalprocess()"/> <input type="submit" name="Reset" class="search" value="Reset"/></td>
   </tr>	
</table>
</form>

<p align="right"><a href="LTA_print.php?site=<?php echo $_REQUEST['site'];?>&emptype=<?php echo $_REQUEST['emptype'];?>&employee_code=<?php echo $_REQUEST['employee_code'];?>&paymonth=<?php echo $_REQUEST['paymonth'];?>&payyear=<?php echo $_REQUEST['payyear'];?>" target="_blank" class="search">Print</a></p>
	
<?php 
//echo $_SESSION['employee_code'];
if($_REQUEST['Search'] || $_REQUEST['page']){?>

<?php //$q3 =DB_query("Select * from deduction_master",$db); $ded_rows=DB_num_rows($q3) ;?>
<?php //$q4 =DB_query("Select * from allowmaster",$db);$all_rows=DB_num_rows($q4);?>
<form action="" method="post" name="myform">
<h3>Salary Details</h3>

	<table width="100%" cellpadding="3" cellspacing="0" border="0" class="thborder">
	<tr>
    	<th width="4%">S. No.</th>
        <th width="7%">Emp Code</th>
        <th>Emp Name</th>
        <th width="10%">Designation</th>
        <th width="7%">Month Days</th>
		<th width="7%">Present Days</th>
	    <th width="7%">Sal Days</th>
        <th width="7%">P.F. No.</th>
		<th width="7%">E.S.I. No.</th>
      <?php
	  		$net_earning=0;
	  		$query_allowances =DB_query("Select * from allowmaster Where allowcode='MED'",$db);
			$row_allowances=DB_fetch_array($query_allowances);	  
		?> 
    	<th><?php echo $row_allowances['allowcode'];?><input name="allowmasterid" type="hidden"  value="<?php echo $row_allowances['id'];?>"/></th><?php //} ?>
		<th width="7%">LTA</th>        
    </tr>
    <?php $LTA_allow_Val=array();$allowance_amount=array();
  	$filter='';
 	if($_SESSION['employee_code']!='All')
   		$filter.=" E.id='".$_SESSION['employee_code']."' ";
   	else
   		$filter.=" 1=1 ";
   
   	if($_SESSION['emptype']!='')
    	$filter.=" and  E.employment_type='".$_SESSION['emptype']."'";
    if($_SESSION['emp_salprocess_site']!='000')
   		$filter.=" and  E.emp_site='".$_SESSION['emp_salprocess_site']."'";
	
	if($month==12){
			$month1=1;
			$year1=$years+1;
		}else{
			$month1=$month+1;
			$year1=$years;
		}
		 
   $searchval=$month1."/01/".$year1;
   	 $GetRecord = "SELECT E.*,S.payslip_month,S.payslip_year,S.workingdays FROM empmaster AS E INNER JOIN master_process_salary AS S ON E.id=S.emp_id WHERE $filter and E.CompanyId='".$_SESSION['ACGCompanyId']."' and E.blocked!=1 and S.payslip_month='".$_REQUEST['paymonth']."' AND S.payslip_year='".$_REQUEST['payyear']."'";
	  $ResultData = DB_query($GetRecord,$db);
	  if(DB_num_rows($ResultData))
	{
	$i=0;
   	  	while($RowData = DB_fetch_array($ResultData))
   	  	{
		$emp_id=$RowData['id'];
		$emp_weekly_off = $RowData['emp_weekly_off'];
		$basic_sal = $RowData['basic_salary'];
		$workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);
		$one_day_sal= round(($basic_sal/$workingdays),2); 
		 $payable_day = payable_day($emp_id,$month, $years,'P',$RowData['doj']);
		// $absent= payable_day($emp_id,$month, $years,'A',$RowData['doj']); 
		// $ACGpaydays2 = Calculate_EmpSalaryDays($emp_id,$month,$years,'P',$emp_weekly_off,$RowData['doj']);
		 //$ACGdeductday = Calculate_deductday($emp_id,$month,$years,'P');
		  //$ACGpaydays1=($ACGpaydays2)-($ACGdeductday+$absent);
		  //if($workingdays<$ACGpaydays1)
		//$ACGpaydays1=$workingdays;
		//$ACGpaydays = $ACGpaydays1;
		$paid_gross=$ACGpaydays*$one_day_sal;
  ?>
				 <tr>
    				<td><input type="text" readonly="" class="input_read" value="<?php echo $i+1;?>" /></td>
        			<td><input type="text" readonly="" class="input_read" value="<?php echo $RowData['emp_code']; ?>" /></td>
       				<td><input type="text" readonly="" class="input_read" value="<?php 
	   					if($RowData['payment_mode']=='Cash')
	   						{echo $RowData['emp_name'];}
	   					else
	   						{echo $RowData['emp_name']."<br/><br/>".$RowData['bank_name']." A/C No. ".$RowData['bank_account'];}
					?>" /></td>
       				<td><input type="text" readonly="" class="input_read" value="<?php echo $s->getField('desigmaster','id',$RowData['designation'],'designame');?>" /></td>
        			<td><input type="text" readonly="" class="input_read" value="<?php echo  $workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);?>" /></td>		   			
					<td><input type="text" readonly="" class="input_read" value="<?php echo $payable_day; ?>" /></td>
		   			<td><input type="text" readonly="" class="input_read" value="<?php echo $RowData['workingdays']; ?>" /></td>
           			<td><input type="text" readonly="" class="input_read" value="<?php echo $RowData['PFno'] ?>" /></td>
              		<td><input type="text" readonly="" class="input_read" value="<?php echo $RowData['ESIno'] ?>" /></td>
					<?php 
					$deduction_amount=array();
					$q1 =DB_query("Select * from allowmaster WHERE allowcode='MED'",$db); 
	  					while($rq1=DB_fetch_array($q1))
	  					{ 
							if(isset($allowance_id))
							{
								$query =DB_query("Select * from emp_salary_revise where emp_id='".$emp_id."' 
								and allowance_deduction='".$rq1['id']."' and all_ded_prefix='A' 
								AND mst_revid='".$allowance_id."'",$db);
							}else{
								$query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' 
								and allowance_deduction='".$rq1['id']."' and all_ded_prefix='A'",$db);
							}
							
							if(DB_num_rows($query))
							{
       	 						while($row=DB_fetch_array($query)){
								
								?>
					<td><input type="text" readonly="" class="input_read" value="<?php  
       							//echo	 $row['all_ded_prefix'];
       							if($row['percentage']==0.00 )
       							{
       								$allowance=($row['percentage_value']/$workingdays)*$workingdays;
								}else {
								$gbasic= round(($paid_gross));
			 						//$allowance=(.01*$gbasic*$row['percentage']*$ACGpaydays)/$workingdays;
									$allowance=(.01*$gbasic*$row['percentage']);
								}
		 
		 						//echo $row['percentage_value']."<br>-----<br>";
		 						  echo  (round($allowance)!=0?round($allowance):'0');
	 
		 						//if($row['all_ded_prefix']=='A')
								$allowance_amount[]=round($allowance);
								?>" />
         						</td>								
       	 						<?php }
								
							} }?>
		<td><input type="text" readonly class="input_read" value="<?php 
		$get_LTA=DB_query("Select * from emp_salary where emp_id='".$emp_id."' and all_ded_prefix='A' and allowance_deduction=101",$db);
	$get_LTAVAl=DB_fetch_array($get_LTA);
	echo $get_LTAVAl['percentage_value'];
	$LTA_allow_Val[]=$get_LTAVAl['percentage_value'];?>" /></td>
      			</tr>     			
		
	<?php $i++;}?>
	<tr>
	<td colspan="9" style="text-align:right; vertical-align:middle;">Total</td>
<td><input type="text" readonly="" class="input_read" value="<?php echo array_sum($allowance_amount);?>" /></td>
<td><input type="text" readonly="" class="input_read" value="<?php echo array_sum($LTA_allow_Val);?>" /></td>
</tr>
   <?php }else{
		echo "<tr bgcolor='#fff'><td colspan='11' align='center'>No Record Found</td></tr>";
	}   
?>
    </table>
	
</form>

    
       <?php }
	   
	    ?>
<script language="javascript">
function LeadData()
{	
	//var test=document.getElementById("SalaryProcessed").value;
	myCheckboxArray = document.myform.elements["SalaryProcessed[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('SalaryProcessed').checked==true)
	{	
		if(t==undefined)
		document.getElementById('SalaryProcessed_'+0).checked=true;		
		for (var i = 0; i < t; i++)
		{
			//if(document.getElementById('process_status_'+i).value=='N'){
				document.getElementById('SalaryProcessed_'+i).checked=true;
			//}else{
			//	document.getElementById('SalaryProcessed_'+i).disabled=true;
			//}
		}	
	}
	else
	{
		if(t==undefined)		
		document.getElementById('SalaryProcessed_'+0).checked=false;		
	
		for (var i = 0; i < t; i++)
		{
			document.getElementById('SalaryProcessed_'+i).checked=false;	
		}
	}
}

function chksalprocess()
{
		var today = new Date();
		var dd = today.getDate();
		var currmonth = today.getMonth()+1; //January is 0!
		var CurrentYear=today.getFullYear();
		
		var selmonth=document.getElementById("paymonth").value;
		var selyear=document.getElementById("payyear").value;
		
		//if(selmonth>=currmonth)
		//{
			//alert("You Can Process Only Previous Month Salary");
			//return false;
		//}
		
	//return false;
}
</script>
</div>
</div>