<link rel="stylesheet" type="text/css" href="css/table_frize_1.css">
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Process Salary</h1>
<?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/SalaryProcess_new&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['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">
 <table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="12%" 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="12%" align="right">Month</td>
    <td width="20%"><select name="paymonth" id="paymonth"  onchange="chk_type_employee();">
 		<?php	$arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","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 width="12%" align="right">Year</td>
    <td><select name="payyear" id="payyear"   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>
</tr>
<tr class="row1">
	<td align="right">Department</td>
	<td><select name="dept" id="dept" onchange="chk_type_dept_employee();" > 
      <option value="0">Select</option>
      <?php 
       $sql_dept=DB_query("select * from deptmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
       while($row_dept=DB_fetch_array($sql_dept))
       {
       	$dep='';
       	if($_REQUEST['dept']==$row_dept['id'])
       		$dep='selected';
      ?>
      <option value="<?php echo $row_dept['id']; ?>" <?php echo $dep; ?>><?php echo $row_dept['deptname']; ?></option>
      <?php } ?>
			</select></td>
    <td align="right">Employee Type</td>
    <td><select name="emptype" id="emptype" onchange="chk_type_employee();" > 
			<option value="R" <?php echo($_REQUEST['emptype']=='R'?'selected':'')?>>Regular Employee</option>
			<option value="C" <?php echo($_REQUEST['emptype']=='C'?'selected':'')?>>Contract Employee</option>
			<option value="P" <?php echo($_REQUEST['emptype']=='P'?'selected':'')?>>Probation Employee</option>
		</select></td>
    <td align="right">Employee</td>
    <td><div id='hid-empdiv'><select name="employee_code" id="employee_code" >
			<option value="All">All</option>
			<?php 
                        if($_REQUEST['paymonth']!='' && $_REQUEST['payyear']!='' && $_REQUEST['emptype']!=''){
                        $chk_date=$_REQUEST['payyear']."-".$_REQUEST['paymonth']."-01";
                        $chk_date1=$_REQUEST['payyear']."-".$_REQUEST['paymonth']."-31";
	                        if($_REQUEST['dept']!='0')
	                        {
				                        $emp_sql = DB_query("SELECT id,emp_code ,emp_name FROM empmaster 
				                        	WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND emp_site='".$_REQUEST['site']."' AND staff_type='".$_REQUEST['emptype']."' and department='".$_REQUEST['dept']."' AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' 
				              ORDER BY emp_name ASC",$db);
			                }
			                else
			                {
			                	 $emp_sql = DB_query("SELECT id,emp_code ,emp_name FROM empmaster 
				                        	WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND emp_site='".$_REQUEST['site']."' AND staff_type='".$_REQUEST['emptype']."' AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' 
				              ORDER BY emp_name ASC",$db);
			                }        
                        }
                        else
                        {
		                        $chk_date=date('Y')."-".date('m')."-01";
		                        $chk_date1=date('Y')."-".date('m')."-31";
		                        $emp_sql=DB_query("SELECT id,emp_code ,emp_name FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND staff_type='Permanent' AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' ORDER BY emp_name ASC",$db);
                        }
			while($emp_row=DB_fetch_array($emp_sql)){?>
			<option value="<?php echo $emp_row['id'];?>"<?php if($_REQUEST['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 colspan="6" align="center"><input type="submit" name="Search" class="search" value="Search" />
      <input type="submit" name="Reset" class="search" value="Reset"/></td>
    </tr>
</table>
</form>

<?php 
//echo $_SESSION['employee_code'];
if($_REQUEST['UnProcess'])
{
	for($i=0;$i<count($_REQUEST['SalaryProcessed']);$i++){
		
		$unprocess_query = "select id from master_process_salary where payslip_month ='".$_SESSION['paymonth']."'and  payslip_year ='".$_SESSION['payyear']."' and emp_id ='".$_REQUEST['SalaryProcessed'][$i]."'";
		$unprocess_query_res = DB_query($unprocess_query,$db) or die(DB_error());
		$unprocess_query_result = DB_fetch_array($unprocess_query_res);
		
		if(DB_num_rows($unprocess_query_res)>0)
		{
			$del_unprocess_query = "delete from master_process_salary where payslip_month ='".$_SESSION['paymonth']."'and  payslip_year ='".$_SESSION['payyear']."' and emp_id ='".$_REQUEST['SalaryProcessed'][$i]."'";
			$del_unprocess_result = DB_query($del_unprocess_query,$db) or die(DB_error());
			if(DB_affected_rows($del_unprocess_result)>0)
			{
				$del_payslip_query = "delete from payslip_salary where mst_prosal in ('".$unprocess_query_result['id']."') and emp_id =".$_REQUEST['SalaryProcessed'][$i]."";
				$del_payslip_res = DB_query($del_payslip_query,$db) or die(DB_error());
			}
		}
 		
 	}
					$s->PageLocation($target_rurl.'&daction=Record Deleted Successfully');

	for($i=0;$i<count($_REQUEST['SalaryProcessed']);$i++){
 		$condition=" payslip_month ='".$_SESSION['paymonth']."' and  payslip_year ='".$_SESSION['payyear']."'  and emp_id ='".$_REQUEST['SalaryProcessed'][$i]."' ";
		$getmst_processid=$s->GetFieldValue('master_process_salary',$condition ,'id');
		$s->DeleteRecord('master_process_salary',$condition);
 		$condition2="mst_prosal in ($getmst_processid) and emp_id  =".$_REQUEST['SalaryProcessed'][$i]."";
		$s->DeleteRecord('payslip_salary',$condition2);
 	}
	$s->PageLocation($target_rurl.'&daction=Record Deleted Successfully');
}

if($_REQUEST['Save'])
{
	$flag = 0;
	$_REQUEST['Search']=1; 	
		 
	for($i=0,$lx=0;$i<count($_SESSION['Mstemp1']);$i++,$lx++)
	{
		if(in_array($_SESSION['Mstemp1'][$i][0],$_REQUEST['SalaryProcessed'])) 
	 	{	
			$data['emp_id'] =$_SESSION['Mstemp1'][$i][0];
			$data['payslip_month'] = $_SESSION['Mstemp1'][$i][1];
			$data['payslip_year'] =$_SESSION['Mstemp1'][$i][2];
			//$data['total_workingday'] = $_SESSION['Mstemp1'][$i][3];
			$data['workingdays'] = $_SESSION['Mstemp1'][$i][4];
 			$data['basic_salary'] = $_SESSION['Mstemp1'][$i][5];
			$data['loan'] =$_SESSION['Mstemp1'][$i][7];
            $data['othe_ded'] =$_SESSION['Mstemp1'][$i][17];
			$data['loan_masterid'] =$_SESSION['Mstemp1'][$i][8];
			$data['advance_balance'] =$_SESSION['Mstemp1'][$i][6];
			$data['balance_loanamt'] =$_SESSION['Mstemp1'][$i][9];
			$data['net_earning'] = $_SESSION['Mstemp1'][$i][10];
			$data['OThours'] = $_SESSION['Mstemp1'][$i][11];
			$data['OTBasicAmount'] = $_SESSION['Mstemp1'][$i][12];
			$data['gross_salary'] = $_SESSION['Mstemp1'][$i][13];
			$data['tds_deduction'] = $_SESSION['Mstemp1'][$i][18];

			$data['locked'] = 'Y';
			$data['created_date'] = date('Y-m-d');
			$data['sunday_deduction_count']=$_SESSION['Mstemp1'][$i][19];
		
		 	//-------------------UPDATE DATA IN --------emp_loan_details And -loan_management---------------------------------+
			$data_loanupdate['paid_status ']='Y';
			$data_loanupdate['balance_amount']=$_SESSION['Mstemp1'][$i][9]-$_SESSION['Mstemp1'][$i][7];
			$cond1="loanid='".$_SESSION['Mstemp1'][$i][8]."' and loan_month ='".$_SESSION['Mstemp1'][$i][1]."' 
			and year(loan_paid_date) ='".$_SESSION['payyear']."'";
			//echo "<pre>";
			//print_r($data_loanupdate);
			$s->RecordEdit('emp_loan_details', $data_loanupdate, $cond1);
		//exit;
			//$getloanamt=$s->GetFieldValue('loan_management',"id='".$_SESSION['Mstemp'][$i][11]."'",'loan_balance');
			//$_SESSION['Mstemp1'][$i][6];
			$data_loan_management['loan_balance']=$_SESSION['Mstemp1'][$i][9]-$_SESSION['Mstemp1'][$i][7];
			$cond2="id='".$_SESSION['Mstemp1'][$i][8]."'";
			
			//echo "<pre>";
			//print_r($data_loan_management);
			$s->RecordEdit('loan_management', $data_loan_management, $cond2);
  	 		
			//--------------------------------------------------------------------------------------------------------------	
			$data['balance_loanamt'] =$data_loan_management['loan_balance'];
			
			//echo "<pre>";
			//print_r($data);
		    $emp_query = "select * from master_process_salary where emp_id='".$data['emp_id']."' and payslip_month='".$_SESSION['paymonth']."'
			 and payslip_year='".$_SESSION['payyear']."'";
			$emp_result = DB_query($emp_query,$db) or die(DB_error());
			if(DB_num_rows($emp_result)>0){
			}
			else 
			{
				$insert=$s->RecordInsert('master_process_salary', $data);
				$last=  DB_Last_Insert_ID($db,'master_process_salary', 'id');
				for($l=0,$j=0;$j<count($_SESSION['Mstemp_paysal']);$j++,$l++)
				{
					if($_SESSION['Mstemp_paysal'][$j][0]==$_SESSION['Mstemp1'][$i][0])
					{
						$data_arr['mst_prosal']=$last;
						$data_arr['emp_id']=$_SESSION['Mstemp_paysal'][$j][0];;
						$data_arr['allowance_id']=$_SESSION['Mstemp_paysal'][$j][1];;
						$data_arr['allowance_amount']=$_SESSION['Mstemp_paysal'][$j][2];;
						$data_arr['allowance_type']=$_SESSION['Mstemp_paysal'][$j][3];
					/*echo "<pre>";
						print_r($data_arr);*/
						
						$insert=$s->RecordInsert('payslip_salary', $data_arr);
					}
				}		
			}
			
 		}	
	}
	$target_rurl="index.php?route=HRModule/SalaryProcess_new&modid=".$modid."&frmid=".$frmid."";
	$s->PageLocation($target_rurl.'&daction=Record Insert Successfully');
}

if(isset($_POST['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'];
	?>

<?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);?>
<?php $q5 =DB_query("SELECT * FROM other_deduction_master WHERE status='A' AND type='D'",$db); $other_dd_rows=DB_num_rows($q5) ;?>
<?php $q6 =DB_query("SELECT * FROM other_deduction_master WHERE status='A' AND type='A'",$db); $other_aa_rows=DB_num_rows($q6) ;?>
<br>
<form action="" method="post" name="myform">
	<div style="width:1250px; margin:0 auto; height:350px; overflow:auto;">
	<table width="140%" cellpadding="3" cellspacing="0" border="0" class="thborder">
	<tr>
	    <th colspan="9"></th>
		<th style="text-align:center" colspan="<?php echo $all_rows+2;?>"><b>EARNINGS</b></th>
		<th ><b>GROSS WAGES</b></th>
		<th style="text-align:center" colspan="<?php echo $ded_rows+$other_dd_rows+4;?>"><b>DEDUCTIONS</b></th>
		<?php if(isset($other_aa_rows) && $other_aa_rows>=1){?>
		<th style="text-align:center" colspan="<?php echo $other_aa_rows+1;?>"><b>ADDITIONS</b></th>
		<?php } ?>		
		<th colspan="6"></th>
	</tr>
	<tr>
    	<th width="2%"><input name="SalaryProcessed" type="checkbox" id="SalaryProcessed" onclick="LeadData()" /></th>
        <th width="4%" >Emp. Code</th>
        <th >Emp. Name</th>
        <th width="5%" >Designation</th>
        <th width="3%" >Month<br>Days</th>
		<th width="3%" >Present<br>Days</th>
	    <th width="3%" >Sal<br>Days</th>
	    <th width="3%" >No. of<br/>Sunday Deduction</th>
        <th width="3%" >P.F. No.</th>
		<th width="3%" >E.S.I. No.</th>
        <!-- <th >Monthly Salary</th> -->
        <th width="3%" >Payable Basic</th>
		<?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))
	  		{ 		  
		?> 
    	<th width="3%">
    		<?php echo $row_allowances['allowcode'];?><input name="allowmasterid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/></th>
		<?php if($row_allowances['allowcode']=='LTA') {?>
		<!--<th>Special Allowance</th>-->
		<?php } ?>
     	<?php } ?>
		<th width="3%">Special Allowance</th>
		<th width="3%">&nbsp;</th>
        <?php 
		$essi='';
		$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)){
			$essi[]=$row_allowances['code'];
			?> 
    	<th width="3%"><?php echo $row_allowances['code'];?><input name="deductionid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/></th>         
     	<?php } ?>
     	<?php 
     	$GetOther_Ddmaster = DB_query("SELECT id,name FROM other_deduction_master WHERE status='A' and type='D' AND CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  				while($RecOthr_Dd=DB_fetch_array($GetOther_Ddmaster))
	  				{?>
                    <th><?php echo ''.$RecOthr_Dd['name'].'';
                   $ddArr[]=$RecOthr_Dd['id'];
					?>
				 </th>
					<?php } ?>		
	    <th width="3%">Adv</th>   
		<th width="3%">Loan</th> 
     	<th width="3%" >Loan Bal.</th>    
     	<th width="3%" >Total<br>Deduction</th>
     	<?php 
     	$GetOther_Amaster = DB_query("SELECT id,name FROM other_deduction_master WHERE status='A' and type='A' AND CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  				while($RecOthr_A=DB_fetch_array($GetOther_Amaster))
	  				{?>
                    <th><?php echo ''.$RecOthr_A['name'].'';
                   $aaArr[]=$RecOthr_A['id'];
					?>

				 </th>
					<?php } ?>
		<th width="3%" >Total<br>Addition</th>
		<th width="3%" >OT<br>Amount</th> 
      	<th width="3%" >Gross<br>Wages</th>    	
    	<!--<th width="3%" >Tds Deduction</th>-->		   	
		<!--<th width="3%" >Net Pay</th>		
     	<th width="3%">Payment Advice Status</th>-->	  
		<th width="3%">Loc</th>
    </tr>
    <?php
         $sql_late_allow="select late_allow from late_count_master order by id desc limit 1";
         $result_late_allow=DB_query($sql_late_allow,$db);
         $rs_late_allow=DB_fetch_array($result_late_allow);
         $late_allowed=$rs_late_allow[0];

  	$filter='';
 	if($_SESSION['employee_code']!='All')
   		$filter.=" id='".$_SESSION['employee_code']."' ";
   	else
   		$filter.=" 1=1 ";
   
   	if($_SESSION['emptype']!='')
    	$filter.=" and  staff_type='".$_SESSION['emptype']."'";
    if($_SESSION['emp_salprocess_site']!='000')
   		$filter.=" and  emp_site='".$_SESSION['emp_salprocess_site']."'";
   	if($_REQUEST['dept']!='0')
   		$filter.=" and  department='".$_REQUEST['dept']."'";
	if($month==12){
			$month1=1;
			$year1=$years+1;
		}else{
			$month1=$month+1;
			$year1=$years;
		}	
	$searchval=$month1."/01/".$year1;
  	 $GetRecord = "Select * from empmaster where  $filter  and blocked!=1 and doj<'".date("Y-m-d",strtotime($searchval))."'";
 	$_SESSION['print_query']= $GetRecord;
	
    $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 "<pre>";
          //  print_r($RowData);

   	  	  $otherded='';
			//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;
				$ltw=0;	
				$emp_id=	$RowData['id'];
				$month1 = $month;
				$years1 = $years;
				//AND locked='Y'
				
				$GetSalryFor = "Select shift_for from shift_master 
				where id='".$RowData['employee_type']."' ";	   	    		
				$ResultSalryFor = DB_query($GetSalryFor,$db);
				$sal_for=DB_fetch_row($ResultSalryFor);

				$GetMonthRevSal = "Select * from empmaster_revised_sal where empid='".$emp_id."' ";	   	    		
				$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 empmaster_revised_sal where empid='".$emp_id."' 
							AND applicable_month='".$m."' AND applicable_year='".$y."' AND log_type='revise'
							 order by id desc limit 0,1";	   	    						
							$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 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'];
					unset($allowance_id);
				}
				$gross_sal = $RowData['gross_sal'];
				$basic_sal = $RowData['basic_salary'];
				$over_timestatus= $RowData['over_time'];
				$emp_weekly_off = $RowData['emp_weekly_off'];	

				$late_half_day=0;
				$late_full_day=0;
				$weekly_off_count=0;
				$total_late_count=0;
				$half_day=0;
				$forgot_punch_approved=0;
				$late_coming_approved=0;


               
				if($sal_for[0]=='Staff')
				{
                    $weeklyoff= worker_holiday_wl($emp_id,$month, $years,'WL',$RowData['doj']);
					// $weeklyoff= CountSatSun($month, $years,$emp_weekly_off ); 
					//$holiday=Count_Holidays($month,$years,$_REQUEST['site']);
					$holiday=payable_day($emp_id,$month, $years,'HO',$RowData['doj']);
					$workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);
					$one_day_sal= $basic_sal/$workingdays;
				}else{
					 $weeklyoff= worker_holiday_wl($emp_id,$month, $years,'WL',$RowData['doj']);
					 $holiday=worker_holiday_wl($emp_id,$month, $years,'HO',$RowData['doj']);

					$workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);
					$workingdays=$workingdays-($weeklyoff+$holiday);
					$one_day_sal= $basic_sal/$workingdays;	
				}
				//echo "week";				  	
				//echo "abs";
				//echo "<br>";
				   $absent= payable_day($emp_id,$month, $years,'A',$RowData['doj']); 
				
				// echo "present";
      			  $payable_day = payable_day($emp_id,$month, $years,'P',$RowData['doj']);

      			  $payable_day_hl= payable_day($emp_id,$month, $years,'HL',$RowData['doj']);
      			  $payable_day+=$payable_day_hl*0.50;
                   

      
                                 $count_half_day = count_half_day($emp_id,$month, $years,'H',$RowData['doj']);
                                 //$half_day = half_day($emp_id,$month, $years,'H',$RowData['doj']);
			   $leave_day=payable_day($emp_id,$month, $years,'L',$RowData['doj']);
			
				//echo "payable";
             /* --------------------  Late Count Starts Here --------------------------- */ 
			     if($RowData['employment_type']!='D')
			     {
			       $total_late_count=late_count($emp_id,$month,$years,$RowData['doj']);
			       if($late_allowed=='') { $late_allowed=0; }
                   if($total_late_count<=$late_allowed)
                   {
                   	 $late_half_day=$total_late_count;
                   }
                   else
                   {
                   	 $late_half_day=$late_allowed;
                   	 $late_full_day=$total_late_count-$late_allowed;
                   }
                 }
                 else
                 {
                 	$late_half_day=0;
                 	$late_full_day=0;
                 } 

             //    echo $late_half_day."#####".$late_full_day; 

			  /* if($late_allowed!='0')
			  {
			    $late_half_day=($total_late_count/$late_allowed);
			  }   */

			 /* --------------------  Late Count Ends Here --------------------------- */   

			 /* ------------------  Weekly leave count Starts Here -----------------*/
              if($RowData['employment_type']!='D')
              {
			   $weekly_off_count=get_weekly_present($emp_id,$month,$years,$RowData['doj']);
			  }  

			  /* ------------------  Weekly leave count Ends Here -----------------*/

		/* ---------------  Approved Forget Attendance,late coming and early departure ------------*/
              $forgot_punch_approved=forgot_punch($emp_id,$month,$years,$RowData['doj']);
              $late_coming_approved=late_approved_count($emp_id,$month,$years,$RowData['doj']);
	  /* ---------------  Approved Forget Attendance,late coming and early departure ------------*/

               //$payable_day+=$forgot_punch_approved+$late_coming_approved;  

				//$tot_payable_day=$payable_day+$weeklyoff+$leave_day+$holiday;
				 $tot_payable_day=$payable_day+$weeklyoff+$leave_day+$holiday+($count_half_day*.50);	
	            //$tot_payable_day=$payable_day+$weeklyoff+$leave_day+$holiday+($count_half_day*.50)	  
				 //echo $payable_day."<br/>".$weeklyoff."<br/>".$holiday."<br/>".$count_half_day*0.50;				 	
				
				$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;    
				}  
				
				$leave_valworker=payable_day_leavetypeworker($emp_id,$month, $years);
				$ltw=$ltw+$leave_valworker;
				/*
				$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+$absent);
				//$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=$tot_payable_day;


					
				
				
				////$ACGpaydays = $ACGpaydays1-($ACGweekly_off+$ACGcl+$ACGho);
					//echo $sal_for[0];
				if($sal_for[0]=='Staff')
				{	
				 	//$ACGpaydays = $ACGpaydays1-($half_day*.50);
				 	//$ACGpaydays = $ACGpaydays1-($half_day*.50)-($late_half_day*0.50)-($late_full_day)-$weekly_off_count;
				 	$ACGpaydays = $ACGpaydays1-($half_day*.50)-($late_half_day*0.50)-($late_full_day)-$weekly_off_count+$forgot_punch_approved+$late_coming_approved;
				 }
				 else
				 {
				 	//$ACGpaydays = $payable_day+$ltw;
				 	$ACGpaydays = $payable_day+$ltw-($late_half_day*0.50)-($late_full_day)-$weekly_off_count+$forgot_punch_approved+$late_coming_approved;
				 }	
                
                 if($ACGpaydays<0)
                 {
                 	$ACGpaydays=0;
                 }
				$paid_gross=$ACGpaydays*$one_day_sal;
				
				$Locked_payment=DB_fetch_array(DB_query("SELECT B.locked FROM payment_revised AS A INNER JOIN payment_revised_details AS B ON A.id=B.payment_revised_id WHERE A.payment_month='".$_REQUEST['paymonth']."' and A.payment_year='".$_REQUEST['payyear']."' and B.empid='".$emp_id."'",$db));
				
				 //$condition_payment="payment_month='".$_REQUEST['paymonth']."' 
				//and payment_year='".$_REQUEST['payyear']."' and empid='".$emp_id."'";
               // $Locked_payment= $s->GetFieldValue('payment_revised_details',$condition_payment ,'locked');
				$statusLocked= $s->GetFieldValue('master_process_salary',$condition ,'status');
				if($statusLocked['status']=='Y')
				$paymentlock="disabled";
				else
				$paymentlock='';				
				?>
		<tr>
    	<td><?php $statusLocked= $s->GetFieldValue('master_process_salary',$condition ,'status');?>
    	 <input name="SalaryProcessed[]" id="SalaryProcessed_<?php echo $i;?>" type="checkbox" value="<?php echo $RowData['id']; ?>" <?php echo $paymentlock; ?> /></td>
        <td><?php echo $RowData['emp_code']; ?></td>
       	<td><?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><?php echo $s->getField('desigmaster','id',$RowData['designation'],'designame');?></td>
        <td><?php echo  $workingdays;?></td>
		<td><?php echo $payable_day; ?></td>
		<td><?php echo $ACGpaydays; ?></td>
		<td><?php echo $weekly_off_count; ?><input type="hidden" name="sunday_ded" value="<?php echo $weekly_off_count; ?>" /></td>
        <td><?php echo $RowData['PFno'] ?></td>
        <td><?php echo $RowData['ESIno'] ?></td>        			
        <td><?php echo round($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))
	  					{ 
	  						//echo $rq1['allowname']."<br>";
							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))
       	 						{
       	 							//echo $emp_id;

       	 							/*------------------  Grade Wise Incentive Amount Starts Here  --------------------*/
       	 							$grade=$s->GetFieldValue('empmaster',"id='".$emp_id."'",'grade');
       	 							$sql_get_inc="select incentive_amt from cal_incentive_grade_wise left join  hr_incentive_cal on hr_incentive_cal.id=cal_incentive_grade_wise.hr_incentive_cal_id where month='".$_REQUEST['paymonth']."' and year='".$_REQUEST['payyear']."' and cal_incentive_grade_wise.gradeid='".$grade."' ";
       	 							$result_get_inc=DB_query($sql_get_inc,$db);
       	 							$rs_get_inc=DB_fetch_array($result_get_inc);
       	 							
       	 							/*  $sql_att_count="select count(*) from daily_attendance where employee='".$emp_id."' and month(attendance_date)='".$_REQUEST['paymonth']."' and year(attendance_date)='".$_REQUEST['payyear']."' and pres_abs in('WL','P') ";
                                      $result_att_count=DB_query($sql_att_count,$db);
                                      $rs_att_count=DB_fetch_array($result_att_count);
                                      $total_present=$rs_att_count[0];
                                      
                                      if($total_present>=25)
                                      {
                                      	$total_inc_amt=$rs_get_inc[0];
                                      }
                                      else
                                      {
                                        $total_inc_amt=0.00;
                                      } */

       	 						/*------------------  Grade Wise Incentive Amount Starts Here  --------------------*/
       	 							//echo $rq1['allowcode']."<br>";							
								?>
       				<td>
         				<?php  
       							//echo	 $row['all_ded_prefix'];
         				         //if($row['percentage'])

         				        if($rq1['allowcode']!='INC')
         				        {
	       							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 $allow=round($row['percentage_value'])."<br>-----<br>";
		 						   echo ($allowance!=0?round($allowance):'-');	 
		 					     }
		 					     else
		 					     {
                                    if($total_inc_amt!=0.00)
                                    {
                                    	$allowance=$total_inc_amt;

                                    }
                                    else
                                    {
                                    	$allowance="0.00";
                                    }
                                    echo $allow =round($allowance)."<br>---------<br>";
                                     echo ($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'],$allow,$row['all_ded_prefix']); ?></td>								
       	 						<?php }								
							}else{echo "<td>-</td>";}							
							if($rq1['allowcode']=='LTA'){?>
					<td><?php 							
							if(isset($allowance_id))
							{
							$dGetSPLAL=$s->GetFieldValue('emp_salary_revise',"emp_id='".$emp_id."' and allowance_deduction='100' and  mst_revid='".$allowance_id."' and all_ded_prefix='A'",'percentage_value');					
							}							
							else
							{
						$dGetSPLAL=$s->GetFieldValue('emp_salary',"emp_id='".$emp_id."' and allowance_deduction='100' and all_ded_prefix='A'",'percentage_value');
						}						
						echo round($dGetSPLAL)."<br>-----<br>";
						$AUT=($dGetSPLAL/$workingdays)*$ACGpaydays;
						echo $AUT=round($AUT);
						$allowance_amount[]=$AUT;
						$_SESSION['Mstemp_paysal'][] =array($emp_id,100,round($AUT),'A');	
							?></td>
					<?php 		}
							
	  					}?>						
					<td><?php 
						if(isset($allowance_id))
							{
							$dGetSPLAL=$s->GetFieldValue('emp_salary_revise',"emp_id='".$emp_id."' and allowance_deduction='100' AND mst_revid='".$allowance_id."' and all_ded_prefix='A'",'percentage_value');						
							}
							else
							{
						$dGetSPLAL=$s->GetFieldValue('emp_salary',"emp_id='".$emp_id."' and allowance_deduction='100' and all_ded_prefix='A'",'percentage_value');
						}
						echo round($dGetSPLAL)."<br>-----<br>";
						$AUT=($dGetSPLAL/$workingdays)*$ACGpaydays;
						echo $AUT=round($AUT);
						$allowance_amount[]=$AUT;
						$_SESSION['Mstemp_paysal'][] =array($emp_id,100,round($AUT),'A');	
							?></td>
					<td>
					<?php echo round($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);
					$t=0; 
	  				while($rq2=DB_fetch_array($q2))
	  				{ 
					if(isset($allowance_id))
							{							
						$query =DB_query("Select * from emp_salary_revise 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))
	 	 			{
			$ded_name=$s->getField('deduction_master','id',$row['allowance_deduction'],'code');
					?>
       				<td>
   					<?php
					//echo $gbasic."--".$row['percentage'];
						//echo $essi[$t]."<br>";			
					if($essi[$t]=='PF') 
					{
						//if($RowData['govt_nom_pf']=='Y')
					//	{	
							if($gbasic<='15000')
							{
								//$allowance=($gbasic*$row['percentage']/100);

								  if($row['percentage']!='0.00')
								  {
                                   $allowance=($gbasic*$row['percentage']/100);
								  }
								  else
								  {
								   $allowance=$row['percentage_value'];
								  } 

								//$at=floor_dec($allowance,2,'.');
								//$at1=floor_dec1($allowance,0,'.');
								//if($at>0)
								//$allowance=$at1+1;
							}
							else
							{
							
								//$allowance=(15000*$row['percentage']/100);
                                   $allowance=$row['percentage_value'];






								//$allowance=(15000*$row['percentage_value']/100);
								//$at=floor_dec($allowance,2,'.');
								//$at1=floor_dec1($allowance,0,'.');
								//if($at>0)
								//$allowance=$at1+1;
							}
						//}
							/*else{
							$allowance=($gbasic*$row['percentage']/100);
							//$at=floor_dec($allowance,2,'.');
							//$at1=floor_dec1($allowance,0,'.');
							//if($at>0)
							//$allowance=$at1+1;
						}*/ 
					}
               else if($essi[$t]=='Coupon')
               {              
                $totaldays=($ACGpaydays2-($weeklyoff+$holiday));
                $allowance=($totaldays*$row['percentage_value']);
                $at=floor_dec($allowance,2,'.');
				$at1=floor_dec1($allowance,0,'.');
					if($at>0)
					$allowance=$at1+1;                
               }
					else 
					{
					  if($row['percentage']!='0.00')
				    	{
					    // $allowance=($gross_salary*$row['percentage']/100);
						 $allowance=($row['percentage']);
					     } 
				    else if($ded_name=='PT')
                    { 
                    /* $proftax=DB_query("SELECT B.amount as amt FROM `professional_tax_details` B 
                     	INNER JOIN `professional_tax` A ON A.id=B.parentid WHERE A.grade=".$RowData['grade']." 
                     	AND site='".$_REQUEST['site']."' AND  ".$gross_salary." BETWEEN B.from_rage  
                     	AND   B.to_range GROUP BY A.id",$db);
                       $proftax_row=DB_fetch_array($proftax);
                       $allowance=$proftax_row['amt']; */

                       $allowance=$row['percentage_value'];                                   
                      }
					else
					$allowance=$row['percentage_value'];
					$at=floor_dec($allowance,2,'.');
					$at1=floor_dec1($allowance,0,'.');
					if($at>0)
					$allowance=$at1+1;
					}
					echo round($allowance);
 					
 					// 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
					{
					?>
					<td>-</td>
					<?php }	$t++;} ?>
					<?php if($ddArr){
					foreach($ddArr As $value){
	
					$GetOther_Dd = DB_query("SELECT B.amount FROM monthly_other_deducation AS A
				INNER JOIN monthly_other_deducation_details AS B
				ON A.id=B.parentid
				WHERE B.other_ded_type='D' AND A.empid='".$emp_id."' AND A.MONTH='".$month."' AND A.YEAR='".$years."' AND B.other_ded='".$value."'",$db);
	  				$RecOther_Dd=DB_fetch_array($GetOther_Dd);
	  				?>
                    <td><?php //$otherdd[$value][]=$RecOther_Dd['amount'];
                    echo ($RecOther_Dd['amount']!=''?$RecOther_Dd['amount']:'-');
                    $otherded=round(($otherded+$RecOther_Dd['amount']),2);
					//$otherded=other_ded_charges($emp_id,$month,$years);
					//echo ($otherded>0?$otherded:'-');
					?>
					</td>
					<?php }
				} ?>
  		 			<td>
					<?php  
						//$AdvLoan=advance_loan($emp_id,$month,$years);
						  $AdvLoan=advance_loan_charges($emp_id,$month,$years);

						  echo $AdvLoan;

						//echo ($AdvLoan[0]>0?$AdvLoan[0]:'-'); 
		 	  		?></td>
					<td><?php  $AdvLoan1=advance_loan($emp_id,$month,$years);
					//echo ($AdvLoan1[0]>0?$AdvLoan1[0]:'-');
					echo $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>&nbsp;<?php echo round(array_sum($deduction_amount),0)+$AdvLoan+$AdvLoan1[0]+$otherded;?></td>
	     			<?php if($aaArr){
	     				$otherdedA=0;
					foreach($aaArr As $value){
						$GetOther_A = DB_query("SELECT B.amount FROM monthly_other_deducation AS A
						INNER JOIN monthly_other_deducation_details AS B
						ON A.id=B.parentid
						WHERE B.other_ded_type='A' AND A.empid='".$emp_id."' AND A.MONTH='".$month."' AND A.YEAR='".$years."' AND B.other_ded='".$value."'",$db);
			  				$RecOther_A=DB_fetch_array($GetOther_A);
			  				?>
		            <td><?php //$otherdd[$value][]=$RecOther_Dd['amount'];
		                    echo ($RecOther_A['amount']!=''?$RecOther_A['amount']:'-');
		                    $otherdedA=round(($otherdedA+$RecOther_A['amount']),2);							
							?>
							</td>
					<?php } }?>
					<td><?php echo $otherdedA;?></td>
					<td>
					<?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');
					?></td>
         		 	<?php  
	   			 		$netpayable=$paid_gross+round(array_sum($allowance_amount)-array_sum($deduction_amount)+$otherdedA-$AdvLoan-$AdvLoan1[0],0);  

				 	/*	if($AdvLoan!=0)
				 		$netpayable=$netpayable-$AdvLoan[0];
						if($AdvLoan1!=0)
				 		$netpayable=$netpayable-$AdvLoan1[0];*/

                  if($otherded!=0)
                  {
                    $netpayable=($netpayable-$otherded)+$OtamtSQL;
                  } 
                  else
                  {
                    $netpayable=$netpayable+$OtamtSQL;	
                  } 
				 	?>       
      				<td><?php echo ($netpayable!=0?round($netpayable):0);?></td>		 
		 			<?php //if($_REQUEST['emptype']=='Temporary'){?> 
					
					 <?php  
		                   $yeargross=$RowData['gross_sal']*12;
		                   if($yeargross>='250000')
		                   $tds_ded_amt	=($yeargross-250000)/12;

		                   $finyear=$_SESSION['YearStart']."-".$_SESSION['YearEnd1'];
		                   $totalinvestment=  $s->GetFieldValue("hr_declaration_head","emp_id='".$emp_id."' and fin_year='".$finyear."'","SUM(rent_total)+SUM(property_total)+SUM(medical_total)+SUM(edu_total)+SUM(insurance_total)");
		                   $monthly_investment=$totalinvestment/12;
		                   if($monthly_investment<=$tds_ded_amt)
		                   $total_ded_amt=($tds_ded_amt-$monthly_investment);
		                   else
		                   	$total_ded_amt=0;
                   ?>
		  			<!--<td><?php $t1=($netpayable+$OtamtSQL)-$total_ded_amt;echo round($t1);?></td>-->
		  			<!--<td><?php echo $tdsamt= round($total_ded_amt,2); ?></td>-->
					<?php //} ?>
			 		<!--<td><?php if($Locked_payment['locked']=='Y') { echo "Generated"; } ?></td>-->
		    		<td> 
					<?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,$AdvLoan1[0],$AdvLoan1[1],$x,$netpayable,$disOThour,$OT,$gross_salary,$Locked,array_sum($allowance_amount),array_sum($deduction_amount),$otherded,$tdsamt,$weekly_off_count);
				//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,$AdvLoan1[0],$AdvLoan1[1],$AdvLoan1[2],array_sum($allowance_amount),array_sum($deduction_amount),$t1,ucwords(number_to_words($t1)),$otherded,$tdsamt);
			$i++;
			$kl++;
			}			
		}
	}else{
		echo "<tr bgcolor='#fff'><td colspan='40' style='text-align:center;'>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>
	<p align="center">
	<?php 		
	if($_REQUEST['employee_code']=='All') { ?>
	<input type="submit" name="Save" class="search" onclick="return chksalprocess()"  value="Process Salary"  />
	 <input type="submit" name="UnProcess" class="search"  value="UnProcess Salary"  />
	 <?php } else if($_REQUEST['employee_code']!='All' && ($Locked=='N' || $Locked=='')) { ?>
	 <input type="submit" name="Save" class="search" onclick="return chksalprocess()"  value="Process Salary"  />
	 <?php }  else if($_REQUEST['employee_code']!='All' && $Locked=='Y')  {?>
	<input type="submit" name="UnProcess" class="search" onclick="return chksalprocess()"  value="UnProcess Salary"  />
	 <?php } ?>
<!--	 <a href="#"  onclick="popup('Print-SalaryProcess.php',600,600) "><input type="button" class="search"  value="Click Here to Download"  /></a>
-->	
</p>

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

<?php //} ?>
  <?php //} ?>	
  
  </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 count=0;

		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;



$('[id^="SalaryProcessed_"]').each(function(){ 
    if($(this).is(':checked'))
    { 
       count+=1; 
    }
    
});

  if(count=='0')
  {
  	alert("Please check atleast one checkbox");
  	return false;
  }

}
function chk_type_employee()
{
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)
	{
           //alert(xmlhttp.responseText);
	  document.getElementById("employee_code").innerHTML=xmlhttp.responseText;
	}
	}
	var site=document.getElementById("site").value;
	var month=document.getElementById("paymonth").value;
	var year=document.getElementById("payyear").value;
	var type=document.getElementById("emptype").value;
	xmlhttp.open("GET","check_data_ajax.php?section=chk_type_employee&site="+site+"&month="+month+"&year="+year+"&type="+type,true);
	xmlhttp.send();
}

function chk_type_dept_employee()
{
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)
	{
           //alert(xmlhttp.responseText);
	  document.getElementById("employee_code").innerHTML=xmlhttp.responseText;
	}
	}
	var site=document.getElementById("site").value;
	var month=document.getElementById("paymonth").value;
	var year=document.getElementById("payyear").value;
	var type=document.getElementById("dept").value;
	xmlhttp.open("GET","check_data_ajax.php?section=dept_wise_employee&site="+site+"&month="+month+"&year="+year+"&type="+type,true);
	xmlhttp.send();
}


</script>
</div>
</div>