<?php
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');
$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
?>
<style type="text/css">
.f11{font-family:Arial; font-size:11px; color:#000000;}
.fill2{font-family:Arial; font-size:12px; color:#000000;}
</style>
<center>
<div style="width:700px; margin:0px auto;">
	<h3><div style="width:auto; color:#006699; font-size:16px; font-weight:900; padding:10px; text-align:center;"><?php echo $CompamiesRow['CompanyName']?> <br />
Salary Details</div></h3>
</div>
	<div width="100%" style="margin:0px auto;">
	<h4>
		<?php 
		$site = $_REQUEST['site'];
		if(isset($site))
		{
			$branch = $s->getField('locations','loccode',$_REQUEST['site'],'locationname');
			echo "Branch:"." ".$branch."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		$emptype = $_REQUEST['emptype'];
		if(isset($emptype))
		{
			echo "Employee Type:"." ".$emptype."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		$paymonth = $_REQUEST['paymonth'];
		if(isset($paymonth))
		{
		?>
		
		<!-- month and year---->
		
		<?php 
			echo "Month:"." ";
			if($paymonth=='1')
			echo "Jan"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='2')
			echo "Feb"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='3')
			echo "March"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='4')
			echo "April"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='5')
			echo "May"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='6')
			echo "June"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='7')
			echo "July"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='8')
			echo "Augst"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='9')
			echo "Sep"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='10')
			echo "Oct"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='11')
			echo "Nov"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($paymonth=='12')
			echo "Dec"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		$payyear = $_REQUEST['payyear'];
		if(isset($payyear))
		{
			echo " "."Year:"." ".$payyear."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		?>
		</h4>
		</div>
	

</center>
<center>
<?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">
<table align="center">
<tr class="row1">
		<td class="tabledata1">
		<h3>Salary Details</h3>
		</td>
</tr>
</table>

	<table width="100%" cellpadding="2" align="center" cellspacing="0" border="1" style="border:1px solid #333333;">	
	<tr style="height:40px;">
		<td class="tabledata" colspan="8">&nbsp;</td>
		<td class="tabledata" colspan="<?php echo $all_rows+2;?>" style="font-size:11px;"><b>EARNINGS</b></td>
		<td class="tabledata" style="white-space:nowrap;font-size:11px;" valign=""><b>GROSS WAGES </b></td>
		<td class="tabledata" colspan="<?php echo $ded_rows+3;?>" style="font-size:11px;"><b>DEDUCTIONS</b>	    </td>
		<td class="tabledata" style="font-size:11px;"><b>TOTAL</b></td>
		<?php if($_REQUEST['emptype']=='Temporary'){ $colspan="colspan='2'";}?>
		<!--<td <?php echo $colspan;?>><?php if($_REQUEST['emptype']=='Temporary'){?>
		<div align="center"><b>OT</b>
		<?php }else  ?>
	    &nbsp;</div></td>-->
		<td class="tabledata">&nbsp;</td>
		<td class="tabledata">&nbsp;</td>
		<td class="tabledata">&nbsp;</td>
		<td class="tabledata" colspan="7">&nbsp;</td>
	</tr>
	<tr style="height:40px;">
        <td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>Emp Code</strong></td>
        <td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>Emp Name</strong></td>
        <td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>Designation </strong></td>
        <td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>Month Days</strong></td>
		<td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>Present Days </strong></td>
	    <td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>Sal Days</strong></td>
        <td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>P.F. No</strong></td>
		<td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>E.S.I. No</strong></td>
        <!-- <td >Monthly Salary</td> -->
        <td class="tabledata" style="white-space:nowrap;font-size:12px;"><strong>Payable  Basic</strong></td>
		<?php
	  		$net_earning=0;
	  		$query_allowances =DB_query("Select * from allowmaster",$db); 
	  		$j=1;
	  		$n=DB_num_rows($query_allowances);
	  		$nx= round(70/$n,2);
	  		while($row_allowances=DB_fetch_array($query_allowances))
	  		{ 		  
		?> 
    	<td class="tabledata" style="font-size:12px;"><strong><?php echo $row_allowances['allowcode'];?><input name="allowmasterid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/></strong></td>
		<?php if($row_allowances['allowcode']=='LTA') {?>
		<!--<td class="tabledata"><strong>Special Allowance</strong></td>-->
		<?php } ?>
     	<?php } ?>
		<td class="tabledata" style="font-size:12px;"><strong>Special Allowance</strong></td>
		<td class="tabledata"><strong>&nbsp;</strong></td>
        <?php $query_allowances =DB_query("Select * from deduction_master",$db); 
	 	   	$n=DB_num_rows($query_allowances);
	   	   	$nx1= round(70/($n+3),1);
	  		while($row_allowances=DB_fetch_array($query_allowances)){?> 
    	<td class="tabledata" style="font-size:12px;"><strong><?php echo $row_allowances['code'];?><input name="deductionid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/></strong></td>         
     	<?php } ?>
	    <td class="tabledata" style="font-size:12px;"><strong>Adv</strong></td> 
		<td class="tabledata" style="font-size:12px;"><strong>Loan</strong></td>      
     	<td class="tabledata" style="font-size:12px;"><strong>Loan Bal</strong></td>    
     	<td class="tabledata" style="font-size:12px;"><strong>Total Deduction</strong></td>
      	<td class="tabledata" style="font-size:12px;"><strong>Gross Wages<?php //if($_REQUEST['emptype']=='Temporary')echo "Gross Wages"; else echo "Net Pay";?></strong></td>
     	<?php //if($_REQUEST['emptype']=='Temporary'){?> 
	 	<!--<td><strong>OT Hours</strong></td>--->
    	<td class="tabledata" style="font-size:12px;"><strong>OT amount</strong></td>
    	<?php //} ?>
    	<?php //if($_REQUEST['emptype']=='Temporary'){?> 
		<td class="tabledata" style="font-size:12px;"><strong>Net Pay</strong></td>
		<?php //} ?>
     	<!--<td class="tabledata" style="font-size:11px;font-size:11px;"><strong>Signature</strong></td>-->  
		<td class="tabledata" style="font-size:12px;"><strong>Loc</strong></td>
		<td class="tabledata" style="font-size:12px;"></td>
    </tr>
    <?php
	$years=$_SESSION['payyear'];
	$month=$_SESSION['paymonth'];
	$_REQUEST['paymonth'];
  	$filter='';
 	if($_REQUEST['employee_code']!='All')
   		$filter.=" id='".$_REQUEST['employee_code']."' ";
   	else
   		$filter.=" 1=1 ";
   
   	if($_REQUEST['emptype']!='')
    	$filter.=" and  employment_type='".$_REQUEST['emptype']."'";
    if($_REQUEST['site']!='000')
   		$filter.=" and  emp_site='".$_REQUEST['site']."'";

  	$GetRecord = "Select * from empmaster where  $filter  and blocked!=1 ";
	
	/////////////.....................showing records which are processed....................////////////////
	$process_query = "select * from master_process_salary where locked='Y'";
	$process_res = DB_query($process_query,$db) or die(DB_error());
	if(DB_num_rows($process_res)>0)
	{
    	$ResultData = DB_query($GetRecord,$db);
		if(DB_num_rows($ResultData))
		{
		$fstatus=1;
	  	$i=0;$kl=0;$_SESSION['Mstemp1']='';
   	  	while($RowData = DB_fetch_array($ResultData))
   	  	{
			//echo "Select * from daily_attendance where  employee='".$RowData['id']."'  and month(attendance_date)='".$month."' and year(attendance_date)='".$years."'";
	  		$CHKDailyEntry =DB_query("Select * from daily_attendance where  employee='".$RowData['id']."'  and month(attendance_date)='".$month."' and year(attendance_date)='".$years."'",$db);
	 		if(DB_num_rows($CHKDailyEntry)>0)
	 		{
    	  		$emp_id=$RowData['id'];
	  			$condition="payslip_month='".$month."' and payslip_year='".$years."' and emp_id='".$emp_id."'";
 	   			$Locked= $s->GetFieldValue('master_process_salary',$condition ,'locked');
	   			if($Locked=='Y')
	    			$fstatus=0;
 	 			
				//if($Locked=='' || $Locked=='N')
	 			//	$fstatus=1;
		  		
				$lt=0;	
				$emp_id = $RowData['id'];
				$month1 = $month;
				$years1 = $years;
				$GetMonthRevSal = "Select * from empmaster_revised_sal where empid='".$emp_id."' AND locked='Y'";	   	    		
				$ResultMonthRSal = DB_query($GetMonthRevSal,$db);
				if(DB_num_rows($ResultMonthRSal)>0){
					$bb = 0;
					for($y=$years1;$y>=2000;$y--){
						for($m=$month1;$m>=1;$m--){
							$GetMonthLSal = "Select * from logreport_empmaster_revised_sal where empid='".$emp_id."' AND applicable_month='".$m."' AND applicable_year='".$y."' AND log_type='rev'";	   	    						
							$ResultMonthLSal = DB_query($GetMonthLSal,$db);
							if(DB_num_rows($ResultMonthLSal)>0){
								$RowData1 = DB_fetch_assoc($ResultMonthLSal);
								$RowData['gross_sal']=$RowData1['gross_sal'];
								$RowData['basic_salary']=$RowData1['basic_salary'];
								$allowance_id=$RowData1['id'];
								$bb=1;
								break;
							}
						}
						if($bb==1){break;}
						$month1=12;
					}
					if($bb==0){
						$GetMonthLSal = "Select * from logreport_empmaster_revised_sal where empid='".$emp_id."' AND log_type='org' ORDER BY id LIMIT 0,1";	   	    						
						$ResultMonthLSal = DB_query($GetMonthLSal,$db);
						$RowData1 = DB_fetch_assoc($ResultMonthLSal);
						$RowData['gross_sal']=$RowData1['gross_sal'];
						$RowData['basic_salary']=$RowData1['basic_salary'];
						$allowance_id=$RowData1['id'];
					}
				}else{
					$RowData['gross_sal']=$RowData['gross_sal'];
					$RowData['basic_salary']=$RowData['basic_salary'];
					$basic_perc=$RowData['basic_perc'];
				}
				$gross_sal = $RowData['gross_sal'];
				$basic_sal = $RowData['basic_salary'];
				$over_timestatus= $RowData['over_time'];
				$emp_weekly_off = $RowData['emp_weekly_off'];
				$workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);
				$one_day_sal= round(($basic_sal/$workingdays),2); 
				$weeklyoff= CountSatSun($month, $years,$emp_weekly_off );  	
				$absent= payable_day($emp_id,$month, $years,'A',$RowData['doj']); 
				$payable_day = payable_day($emp_id,$month, $years,'P',$RowData['doj']);
				$holiday=Count_Holidays($month,$years);	
				
				$leave_sql="Select * from leavemaster";
				$leave_res=DB_query($leave_sql,$db);  
				while($leave_row=DB_fetch_array($leave_res))
				{
					$leave_val=payable_day_leavetype($emp_id,$month, $years,$leave_row['id']);
					$lt=$lt+$leave_val;   
				}  
				
				
				/*
				$payable_day = payable_day($emp_id,$month, $years,'P');
				$holiday=Count_Holidays($month,$years);	
				$leave_sql="Select * from leavemaster";
				$leave_res=DB_query($leave_sql,$db);  
				while($leave_row=DB_fetch_array($leave_res))
				{
					$leave_val=payable_day_leavetype($emp_id,$month, $years,$leave_row['leavecode']);
					$lt=$lt+$leave_val;   
				}  
				$weeklyoff= CountSatSun($month, $years,$emp_weekly_off );
				$lt=$lt+$weeklyoff;	   
				$absent= payable_day($emp_id,$month, $years,'A');    
				$absent_total_days =$workingdays-$absent-($payable_day+$holiday+$lt ); 
				$absent_withoutinfo=$workingdays -($payable_day+$holiday+$lt );  
				$ACGpaydays=$workingdays- $absent_withoutinfo;
		
				*/
				//echo $emp_weekly_off;

				$ACGpaydays2 = Calculate_EmpSalaryDays($emp_id,$month,$years,'P',$emp_weekly_off,$RowData['doj']);
				Calculate_cl($emp_id,$month,$years,$ACGpaydays2,$workingdays);
				//$ACGpaydaysCL = Calculate_EmpSalaryDaysCL($emp_id,$month,$years,'P',$emp_weekly_off);
				$ACGdeductday = Calculate_deductday($emp_id,$month,$years,'P');
				$ACGpaydays1=($ACGpaydays2)-$ACGdeductday;
				//$ACGweekly_off = Calculate_weekly_off($emp_id,$month,$years,$ACGpaydays1,$workingdays);
				//$ACGweekly_off=
				//$ACGho = Calculate_ho($emp_id,$month,$years,$ACGpaydays1,$workingdays);
				////$ACGcl = Calculate_cl($emp_id,$month,$years,$ACGpaydays1,$workingdays);
				##### Calculate cl from leave apply######################
				//Calculate_cl($emp_id,$month,$years,$ACGpaydays1,$workingdays);
				
				if($workingdays<$ACGpaydays1)
					$ACGpaydays1=$workingdays;
				
				////$ACGpaydays = $ACGpaydays1-($ACGweekly_off+$ACGcl+$ACGho);
				$ACGpaydays = $ACGpaydays1;
				$paid_gross=$ACGpaydays*$one_day_sal;
				?>
				 <tr style="height:40px;">
        			<td class="f11"><?php echo $RowData['emp_code']; ?>&nbsp;</td>
       				<td class="f11">
					<?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 class="f11"><?php echo $s->getField('desigmaster','id',$RowData['designation'],'designame');?></td>
        			<td class="f11"><?php echo  $workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);?></td>
		   			<!--<td><?php echo $ACGpaydays2; ?><br />CL+EL+SL&nbsp;:&nbsp;<?php echo $lt; ?><br />Adj&nbsp;:&nbsp;<?php ////echo (-($ACGweekly_off+$ACGcl+$ACGho)); ?><?php echo (-($ACGweekly_off+$ACGho)); ?><br />Ded&nbsp;:&nbsp;<?php echo $ACGdeductday; ?></td>-->
					<td class="f11"><?php echo $payable_day; ?></td>
		   			<td class="f11"><?php echo $ACGpaydays; ?></td>
           			<td class="f11"><?php echo $RowData['PFno'] ?>&nbsp;</td>
              		<td class="f11"><?php echo ceil($RowData['ESIno']) ?>&nbsp;</td>
        			<!--<td><?php echo $RowData['gross_sal']; ?></td> -->
        			<td class="f11">
					<?php 
						echo $RowData['basic_salary']."<br>----------<br>";
						echo $gbasic= round(($paid_gross));;
					?>
					</td>
              		<?php 
					$deduction_amount=array();$allowance_amount=array();
						$q1 =DB_query("Select * from allowmaster",$db); 
	  					while($rq1=DB_fetch_array($q1))
	  					{ 
							if(isset($allowance_id))
							{
								$query =DB_query("Select * from logreport_empmaster_revi_sal_allowances 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 class="f11">
         						<?php  
       							//echo	 $row['all_ded_prefix'];
       							if($row['percentage']==0.00 )
       							{
       								$allowance=($row['percentage_value']/$workingdays)*$ACGpaydays;
								}else {
			 						//$allowance=(.01*$gbasic*$row['percentage']*$ACGpaydays)/$workingdays;
									$allowance=(.01*$gbasic*$row['percentage']);
								}
		 
		 						echo $row['percentage_value']."<br>----------<br>";
		 						echo (round($allowance)!=0?round($allowance):'-');
	 
		 						//if($row['all_ded_prefix']=='A')
								$allowance_amount[]=round($allowance);
								
								
								
								
								/*	else
								$deduction_amount[]=round($allowance);*/
								$_SESSION['Mstemp_paysal'][] =array($emp_id,$row['allowance_deduction'],round($allowance),$row['all_ded_prefix']); ?>
								</td>
								
       	 						<?php }
								
							}else{echo "<td>-</td>";}
							
							if($rq1['allowcode']=='LTA'){?>
							<!--<td><?php 
						$dGetSPLAL=$s->GetFieldValue('emp_salary',"emp_id='".$emp_id."' and allowance_deduction='100' and all_ded_prefix='A'",'percentage_value');
						echo $dGetSPLAL."<br>-----<br>";
						$AUT=($dGetSPLAL/$workingdays)*$ACGpaydays;
						echo round($AUT,2);
						$allowance_amount[]=$AUT;
						$_SESSION['Mstemp_paysal'][] =array($emp_id,100,round($AUT),'A');	
							?>
							</td>-->
					<?php 		}
							
	  					}?>
						
						<td class="f11"><?php 
						$dGetSPLAL=$s->GetFieldValue('emp_salary',"emp_id='".$emp_id."' and allowance_deduction='100' and all_ded_prefix='A'",'percentage_value');
						echo $dGetSPLAL."<br>-----<br>";
						$AUT=($dGetSPLAL/$workingdays)*$ACGpaydays;
						echo round($AUT,2);
						$allowance_amount[]=$AUT;
						$_SESSION['Mstemp_paysal'][] =array($emp_id,100,round($AUT),'A');	
							?></td>
					<td class="f11">
					<?php echo $RowData['gross_sal']."<br>------------<br>";echo round($gross_salary=$gbasic+array_sum($allowance_amount),2);?>
					</td>
       				<?php 
					//------------------------------------------------------------------------------------------
		
  					$q2 =DB_query("Select * from deduction_master",$db); 
	  				while($rq2=DB_fetch_array($q2))
	  				{ 
					if(isset($allowance_id))
							{
								$query =DB_query("Select * from logreport_empmaster_revi_sal_allowances where emp_id='".$emp_id."' and allowance_deduction='".$rq2['id']."' and all_ded_prefix='D' AND mst_revid='".$allowance_id."'",$db);
							}else{
								$query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction='".$rq2['id']."' and all_ded_prefix='D'",$db);
							}
					
	    			
					if(DB_num_rows($query))
					{
       	 			while($row=DB_fetch_array($query))
	 	 			{?>
       				<td class="f11">
   					<?php  
 					// echo	 '==>'.$row['percentage'];
					echo $allowance=$row['percentage_value'];
       				/*if($row['percentage']==0.00 )
       				{
						$allowance=($row['percentage_value']/$workingdays)*$ACGpaydays;
					}else{
						$allowance=.01*($gbasic+array_sum($allowance_amount))*$row['percentage'];	
					}
					echo $allowance;
		  			if(strtolower($rq2['name'])=='pf' && $allowance!=0)
		   			{
		 	 			if($gbasic>=6500)
						{
 		   					echo round(6500*.0833);
							echo "<br>";
							echo round(6500*.0367);
							echo "<br>";
							echo $allowance=(round( 6500*.0833)+round( 6500*.0367));
						}else{
		   					echo round($gbasic*.0833);
							echo "<br>";
							echo round($gbasic*.0367);
							echo "<br>";
							echo $allowance=(round($gbasic*.0833)+round($gbasic*.0367));
						}
					}else{
		 		  		echo (round($allowance)!=0?round($allowance):'-');
		 			}*/
					$deduction_amount[]=round($allowance);
					/* if($row['all_ded_prefix']=='A') 
					$allowance_amount[]=round($allowance);
					else*/
			 		$_SESSION['Mstemp_paysal'][]=array($emp_id,$row['allowance_deduction'],round($allowance),$row['all_ded_prefix']);?>
					</td>
       	 			<?php }
					}else{echo "<td>-</td>";}
	  				}?>
  		 			<td>
					<?php 
						//$AdvLoan=advance_loan($emp_id,$month,$years);
						$AdvLoan=advance_loan_charges($emp_id,$month,$years);
						echo ($AdvLoan[0]>0?$AdvLoan[0]:'-');
		 	  		?>
					</td>
					<td><?php $AdvLoan1=advance_loan($emp_id,$month,$years);
					echo ($AdvLoan1[0]>0?$AdvLoan1[0]:'-');
					?></td>
		 			<td>
					<?php 
					//$x=EmpAdvanceBalanceAmount($emp_id,$AdvLoan[1],$month);
					$x=EmpBalanceAmount($emp_id,$AdvLoan1[1],$month);
		  				echo ($x>0?$x:'-');
		 		 	?>
					</td>  
	     			<td class="f11">&nbsp;<?php echo round(array_sum($deduction_amount),0)+$AdvLoan[0];?></td>
         		 	<?php  
	   			 		$netpayable=$paid_gross+round(array_sum($allowance_amount)-array_sum($deduction_amount),0);   
				 		if($AdvLoan!=0)
				 		$netpayable=$netpayable-$AdvLoan[0];
				 	?>       
      				<td class="f11"><?php echo ($netpayable!=0?round($netpayable):0);?>&nbsp;</td>
					
					
		 
		 			<?php //if($_REQUEST['emptype']=='Temporary'){?> 
					<td class="f11">
					<?php 
					if($month<10)
					{
						$monthforot='0'.$month;
					}
					else
					{
						$monthforot=$month;
					}
				echo	$OtamtSQL=$s->GetFieldValue('ot_management',"emp_id='".$emp_id."' AND month1='".$monthforot."' AND year1='".$years."'",'ot_amr');
					?>
					
					
					
					
					
					&nbsp;</td>
		  			<td class="f11">
						<?php $t1=$netpayable+$OtamtSQL;
          				echo round($t1);?>
					&nbsp;</td>
					<?php //} ?>
		    		<!--<td class="fll">&nbsp;</td>-->
					<td class="f11"> 
					<?php 
	    			$condition="payslip_month='".$month."' and payslip_year='".$years."' and emp_id='".$emp_id."'";
 					$Lockedid= $s->GetFieldValue('master_process_salary',$condition ,'id');
					$_SESSION['AcgMst_Process_Salary'][]= $Lockedid;
					$_SESSION['AcgMst_Emp_Process_Salary'][]= $emp_id;
					echo ($Locked==''?'N':'Y');
					//echo  $s->getField('master_process_salary','payslip_month',$month,'locked'); ?>&nbsp;
					<input type="hidden" name="process_status" id="process_status_<?php echo $i;?>" value="<?php echo ($Locked==''?'N':'Y');?>" />
					</td>
      			</tr>
       			
				<?php 
	  			$_SESSION['Mstemp1'][$kl]=array($RowData['id'],$month,$years,$workingdays,$ACGpaydays,$gbasic,$AdvLoan[0],$AdvLoan[1],$x,$netpayable,$netpayable,$disOThour,$OT,$gross_salary,$Locked,array_sum($allowance_amount),array_sum($deduction_amount));
				//echo "<pre>";
    			//print_r($_SESSION['Mstemp1']);
	
   				// $_SESSION['Mstemp1'][$kl]=array($RowData['id'],$month,$years,$workingdays, $ACGpaydays,$gbasic,$AdvLoan[0],$x,$netpayable,$OTHOUR,$OT );

				$_SESSION['Mstemp'][]=array($RowData['id'],$month,$years,$gbasic,$workingdays,'',0,0,$OT,0,$AdvLoan[0],$AdvLoan[1],$AdvLoan[2],array_sum($allowance_amount),array_sum($deduction_amount),$t1,ucwords(number_to_words($t1)));
			$i++;
			$kl++;
			}
			
		}
	}else{
		echo "<tr><td colspan=30>No Record Found</td></tr>";
	} 
  }
//if($fstatus==0){
?>
<!--<tr><td colspan="28"> 
	<?php   $m=date('m')-1;
 
	//if($month!=date('m') && $years!=date('Y') && $Locked!='Y')
	///{?>
 	<?php //} ?>
</td></tr>-->
<?php //}?>
    </table>
	</div>
	</td>
</tr>
</table>


<?php // echo DB_num_rows($CHKDailyEntry);
 
//	 if( DB_num_rows($CHKDailyEntry)>0){
	 
	 //if($Locked!='Y'){
	 ?>

<?php //} ?>
  <?php //} ?>	
  
  </form>
    
</center> 
       
<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>
	<?php 
$filename = "salary"; 
header("Content-Type: application/x-msdownload");	
//header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
?>