<?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);
  $sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);

$arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");

?>
<?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) ;?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Salary Register</title>

<style type="text/css" media="print">
  @page port {size: portrait;}
@page land {size: landscape;}
 .portrait {page: port;}
.wrapper {page: land;}

</style>

<style type="text/css"> 
@print {size: landscape; margin:10px;}

@media print{
body{ margin:0px; padding:0px;  font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}

h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

h1{
  font-size: 20px; line-height: 24px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
thead{display: table-header-group;}
.wrapper{width:99%; height: auto; float:left; border:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left; position: relative;
}
 .div_first .left
  {
    width:18%; text-align:left; height:auto; vertical-align:middle; height:auto; padding: 1%; float:left;
  }
  .div_first .middle
  {
    width:58%; text-align:center; padding: 1%; margin:0 auto; float: left;
  }
  .div_first .right
  {
    width:18%; text-align:right; padding: 1%; float: left;
  }

.div_first .full{text-align: center; border: 0;}
.div_second, .div_third, .div_forth{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  /*border-bottom: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 0px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
.div_second table tr:last-child td{border-bottom:0;}
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color:transparent; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td{border-bottom:none;}

.div_forth table tr th, .div_forth table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_forth table tr th{background-color: #ccc; text-align: left;}
.div_forth table tr th:last-child, .div_forth table tr td:last-child{border-right:none;}
.div_forth table tr:last-child td{border-bottom:none;}

.f12{ font-weight: bold; color:#000; font-size:12px;}
.f11{color:#000; font-size:12px; font-weight: normal; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:70%;}
.mt28{margin-top:0px; width:100%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:8%;}
.wdt2{width:100px;}
.wdt3{width: 66px;}
.wdt4{width: 80px;}
.wdt5{width: 52px;}
.wdt6{width: 60px;}
.tab-wdth{width:100%;}
}

@media screen{
/* CSS Document */
body{ margin:0px; padding:0px; background-color:#fff; font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}
h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

#foo{width:1070px; height: auto; margin:0px auto;}
.wrapper{width:1070px; height: auto; margin:10px auto; border-top:#000000 1px solid;}

h1{
  font-size: 24px; line-height: 28px;
  font-weight:bold;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;  
}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left; position: relative; display: table;
}
.div_first .full{text-align: center; border: 0; margin:10px 0 0;}
.div_first .left, .div_first .middle, .div_first .right{float: left; display: table-cell; vertical-align: middle;}
.div_first .left
{
  width:18%; text-align:center; height:auto; vertical-align:middle; padding: 1%; 
}
.div_first .middle
{
  width:58%; text-align:center; padding: 1%; position: relative; margin:0 auto;
}
.div_first .right
{
  width:18%; text-align:center; padding:1%; 
}
.div_second, .div_third, .div_forth{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;*/
  border-top: #000000 1px solid;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 0px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{background-color: #ccc; text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
/*.div_second table tr:last-child td{border-bottom:0;}*/
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color: #ccc; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td{border-bottom:none;}

.div_forth{border-bottom:#000000 1px solid;}

.f12{font-weight: bold; color:#000; font-size:12px;}
.f11{ color:#000; font-size:12px; font-weight: normal; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:100%;}
.mt28{margin-top:0px; width:90%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:10%;}
.wdt2{width:180px;}
.wdt3{width: 66px;}
.wdt4{width: 120px;}
.wdt5{width: 52px;}
.wdt6{width: 70px;}
.panel{width:100%; float:left; overflow:auto;}
.tab-wdth{width:140%;}
}
</style>
</head>
<body>
<div id="foo">
  <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>

<div class="wrapper">
<div class="div_first">
<?php $logoImage=($CompamiesRow['CompanyLogo']=='')?'electra.jpg':$CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>
      <div class="middle"><?php 
    if($CompamiesRow['CompanyName']!="") {echo "<h1>".$CompamiesRow['CompanyName']."</h1>"; } else { echo "";}
    
    if($InoRow['deladd1']!="") { echo $InoRow['deladd1']; } else { echo "";}
    if($InoRow['deladd2']!="") { echo ", ". $InoRow['deladd2']; } else { echo "";}
    if($InoRow['deladd3']!="") { echo ", ". $InoRow['deladd3']; } else { echo "";}
    if($InoRow['city']!="") { echo ", ". $s->getFieldValue("city_master", "id='".$InoRow['city']."'", "city"); } else { echo "";}
    if($InoRow['pincode']!="") { echo " - ".$InoRow['pincode']; } else { echo "";}
    if($InoRow['state']!="") { echo ", ". $s->getFieldValue("state_master", "id='".$InoRow['state']."'", "state"); } else { echo "";}
    if($InoRow['country']!="") { echo ", ". $s->getFieldValue("country_master", "id='".$InoRow['country']."'", "country");
    
     } else { echo "";}
    ?>
     <div class="full"><span class="f11"><?php echo "Phone No.:".$CompamiesRow['Phone'].",   Fax No.: ".$CompamiesRow['fax'].", Email ID.: ".$CompamiesRow['email'].",   Website: ".$CompamiesRow['website']; ?><br>
  <?php  echo $_SESSION['mess']; ?>
  </span></div>
      <h2>Salary Details</h2>
      </div>
      <div class="right"></div>
</div>

<div class="div_second">
<div class="panel">
	<table class="tab-wdth" cellpadding="3" align="center" cellspacing="0" border="0">	
	<tr class="f12">
		<th colspan="8">&nbsp;</th>
		<th colspan="<?php echo $all_rows+2;?>" style="font-size:11px;"><b>EARNINGS</b></th>
		<th style="white-space:nowrap;font-size:11px;" valign=""><b>GROSS WAGES</b></th>
		<th colspan="<?php echo $ded_rows+$other_dd_rows;?>"><b>DEDUCTIONS</b></th>
		<?php if(isset($other_aa_rows) && $other_aa_rows>=1){?>
		<th colspan="<?php echo $other_aa_rows;?>"><b>ADDITIONS</b></th>
		<th colspan="3"></th>
		<?php } ?>		
		<?php if($_REQUEST['emptype']=='Temporary'){ $colspan="colspan='2'";}?>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>	
		<th>&nbsp;</th>	
    <th colspan="4">&nbsp;</th> 
	</tr>
	<tr class="f12">
    <th><strong>Emp Code</strong></th>
    <th><strong>Emp Name</strong></th>
    <th><strong>Designation </strong></th>
    <th><strong>Month Days</strong></th>
    <th><strong>Present Days </strong></th>
    <th><strong>Sal Days</strong></th>
    <th><strong>P.F. No</strong></th>
    <th><strong>E.S.I. No</strong></th>      
    <th><strong>Payable Basic</strong></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))
	  		{ 
	  		$rowallowance_id[]=$row_allowances['id'];		  
		?> 
	  <th><strong><?php echo $row_allowances['allowcode'];?><input name="allowmasterid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/></strong></th>	
     	<?php } ?>
    <th><strong>Special Allowance</strong></th>
    <th><strong>&nbsp;</strong></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'];
			$deductionid[]=$row_allowances['id'];
			?> 			 
	  <th><strong><?php echo $row_allowances['code'];?><input name="deductionid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/></strong></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 '<strong>'.$RecOthr_Dd['name'].'</strong>';
                    $ddArr[]=$RecOthr_Dd['id'];
					?>
				 </th>
		<?php } ?>
	       <th><strong>Adv</strong></th> 
		     <th><strong>Loan</strong></th>      
     	   <th><strong>Loan Bal</strong></th>    
     	    <th><strong>Total Deduction</strong></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 '<strong>'.$RecOthr_A['name'].'</strong>';
                   $aaArr[]=$RecOthr_A['id'];
					?>

				 </th>
					<?php } ?>
					<th><strong>Total Addition</strong></th>
            <th><strong>OT Amount</strong></th>
      	<th><strong>Gross Wages</strong></th>
         <th><strong>thS Deduction</strong></th>
        <th><strong>Reserve Pay</strong></th>       
		    <th><strong>Net Payable</strong></th>
    </tr>
         <?php
        // echo "<pre>";
         //print_r($_SESSION['emp_deduction1']);
            $data_array=$_SESSION['emp_data'];
            if(!empty($_SESSION['emp_data']))
            {
            foreach($data_array as $key=>$value)
            {
          ?>
				 <tr class="f11">
        			<td class="f11"><?php echo $value['emp_code']; ?></td>
       				<td class="f11"><?php echo $value['emp_name']; ?></td>
       				<td class="f11"><?php echo $value['desgination']; ?></td>
        			<td class="f11"><?php echo $value['monthdays']; ?></td>
		   			  <td class="f11"><?php echo $value['paydays']; ?></td>
		   			  <td class="f11"><?php echo $value['working_days']; ?></td>
           		<td class="f11"><?php echo $value['pfno']; ?></td>
           		<td class="f11"><?php echo $value['ESI']; ?></td>
           		<td class="f11"><?php echo $basic[]= $value['basic_sal']; ?></td>
           			<?php if(!empty($rowallowance_id)){
           			foreach($rowallowance_id as $key1=>$value1)
                      {
                      
                      	$amt=$_SESSION['emp_allowance'][$value['empid']][$value1];
                      	$earning[$value1][]=$amt;
                       ?>  
           		<td class="f11"><?php echo $amt; ?></td>
           			<?php } } ?>
              <td class="f11"><?php echo $earning_special[]=$value['special_allowance'] ?></td>        			
        			<td class="f11"><?php echo $earning_gross[]= $value['gross_amt'] ?></td> 
        			    <?php if(!empty($deductionid)){
        			    foreach($deductionid as $key1=>$val1)
					    {
					    	$amt1=$_SESSION['emp_deduction1'][$value['empid']][$val1];
					    	$earning_deducation[$val1][]=$amt1;
					    ?>
        			<td class="f11"><?php echo $amt1; ?></td>
							<?php } } ?>	
       	 			 <?php if(!empty($ddArr)){
       	 			 foreach($ddArr as $key1=>$val2){
                          $amt2=$_SESSION['emp_deduction2'][$value['empid']][$val2];
                          $earning_deducation_part2[$val2][]=$amt2;
       	 			 	?>
       	 			 <td class="f11"><?php echo $amt2; ?></td>
       	 			 <?php } } ?>	
       	 			 <td class="f11"><?php echo $advance_amt[]= $value['advance_amt']; ?></td>
                     <td class="f11"><?php echo $loan_addition_amt[]=$value['loan']; ?></td>
                     <td class="f11"><?php echo $load_balance_amt[]=$value['bal_loan']; ?></td>  
                     <td class="f11"><?php echo $total_deduction_amt[]= $value['total_deduction']; ?></td> 
                      <?php if(!empty($aaArr)){
                       foreach($aaArr as $key2=>$val21)
                      {
                      	$amt3=$_SESSION['emp_addtion'][$value['empid']][$val21];
                      	$other_addtion_amt[$val21][]=$amt3;
                      	?>
                         <td class="f11"><?php echo $amt3; ?></td> 
						<?php } } ?>	
						 <td class="f11"><?php echo $addition_amt_total[]=$value['addtion_amt']; ?></td> 
             <td class="f11"><?php echo $total_other_ded[]=$value['other_ded']; ?></td> 
						  <td class="f11"><?php echo $total_gross_amt[]=$value['total_gross']; ?></td> 
		                   <td class="f11"><?php echo $reserve_amt[]=$value['reverse']; ?></td> 
                        <td class="f11"><?php echo $total_tds_ded[]=$value['tds_ded']; ?></td>
		                    <td class="f11"><?php echo $total_net_payable[]=$value['netpayble']; ?></td> 
		                     
	</tr>
	<?php }  ?>
 <tr class="f11">
 <td></td>
 <td></td>
 <td></td>
 <td></td>
 <td></td>
 <td></td>
 <td></td>
 <td class="f11" style="text-align:right"><strong>Total</strong></td>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($basic),2); ?></strong></td>
 <?php 
if(!empty($rowallowance_id)){
 foreach($rowallowance_id as $key=>$value)
 {
 ?>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($earning[$value]),2); ?></strong></td>
 <?php } } ?>  
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($earning_special),2); ?></strong></td>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($earning_gross),2); ?></strong></td>
 <?php if(!empty($deductionid)){
  foreach($deductionid as $key=>$val)
  {
  ?>
  <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($earning_deducation[$val]),2); ?></strong></td>
  <?php } } ?>
</td>
  <?php if(!empty($ddArr)) { foreach($ddArr as $key1=>$val1){?> 
  <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($earning_deducation_part2[$val1]),2); ?></strong></td>
  <?php } } ?>
</td>
<td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($advance_amt),2); ?></strong></td>
<td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($loan_addition_amt),2); ?></strong></td>
<td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($load_balance_amt),2); ?></strong></td>
<td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($total_deduction_amt),2); ?></strong></td>
 <?php if(!empty($aaArr)){
  foreach($aaArr as $key2=>$val2){?>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($other_addtion_amt[$val2]),2); ?></strong></td>
 <?php } } ?>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($addition_amt_total),2); ?></strong></td>
  <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($total_other_ded),2); ?></strong></td>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($total_gross_amt),2); ?></strong></td>
  <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($total_tds_ded),2); ?></strong></td>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($reserve_amt),2); ?></strong></td>
 <td class="f11" style="text-align:right"><strong><?php echo number_format((float)array_sum($total_net_payable),2); ?></strong></td>  
 </tr>
<?php } ?>
		
    </table>
	</div>
       
</div>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
  
</script>

</div>
</body>
</html>
	