<?php //error_reporting(0);
$PageSecurity = 3;
 include ('includes/session.inc');
  include ('includes/function_lib.php');
  include('includes/fun-php.php');
include('includes/fun-HRClass.php');

 global $db;
  echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';

      $sql=$_SESSION['query'];
       $years=$_SESSION['year'];
	   $month=$_SESSION['month']; 
	   
	    $days_in_month=cal_days_in_month(CAL_GREGORIAN ,$month , $years );
		$timestamp = mktime(0, 0, 0, $month, 1);
		$monthName = date('M', $timestamp );
		
		//echo $sql;
	   $result=DB_query($sql,$db);

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

<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>

<!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>Stock Ledger 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: portrait; 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;}
}

@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;}
}
</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>OT Summary For The Month Of <?php echo $monthName?></h2>
      </div>
      <div class="right"></div>
</div>

<div class="div_second">
 <table width="100%" border="0" cellpadding="3" cellspacing="0">
 <thead>
  <tr class="f12">
    <th>Employee Name</th>
	<th width="10%">Employee Code</th>
    <th width="10%">Total OT Hours/Days</th>
	<th width="10%">Wages Rate</th>
    <th width="10%">OT Amount</th>
	<th width="25%">Signature</th>
   </tr>
  </thead>
  <tbody>
<?php 
	   while($myrow=DB_fetch_array($result))
	   {
	 		$emp_id=$myrow['employee_id'];
			$emp_name=$myrow['emp_name'];
			$emp_code=$myrow['emp_code'];
			$emp_status=$myrow['shift_for'];
			$emp_week_off=$myrow['emp_weekly_off'];
			$week_off_day=GetDay($emp_week_off);
			$gross_salary=$myrow['gross_sal'];
			$emp_status_id=$myrow['employee_type'];

			$startdate=firstOfMonth($month,$years);
			$end_date=lastOfMonth($month,$years);
			
			if($emp_status=='Worker')
			{
				$TotalOt=getOTHours($emp_id,$month,$years);
				
				if($gross_salary>5000)
				$wages_rate=5000;
				else
				$wages_rate=$gross_salary;
				
				
				
				$total_work_hrs_in_month='00:00';
				for($i=$startdate;$i<=$end_date;$i++)
				{
					
					//echo $i;
					//echo DayOfDate($i)."<br>=============";
					//echo $week_off_day."<br>";
					if(DayOfDate($i)==$week_off_day)
					{
						$array_of_week_off[]=$i;
						$check_week_off_present="Select work_hrs,pres_abs from daily_attendance where attendance_date='".$i."' and employee='".$emp_id."'";
						//echo $check_week_off_present."<br>";
						$check_result=DB_query($check_week_off_present,$db);
						//echo DB_num_rows($check_result);
						if(DB_num_rows($check_result)>0)
						{
							$check_row=DB_fetch_array($check_result);
							//echo $check_row['pres_abs']."<br>";
							if($check_row['pres_abs']=='P')
							{
								$work_hours=$check_row['work_hrs'];
								//echo $work_hours."<br>";
								$total_work_hrs_in_month_BRK=explode(':',$total_work_hrs_in_month);
								//echo $total_work_hrs_in_month_BRK[0];
								$work_hours_BRK=explode(':',$work_hours);
								//echo $work_hours_BRK[0];
								$total_hours=$total_work_hrs_in_month_BRK[0]+$work_hours_BRK[0];
								$total_min=$total_work_hrs_in_month_BRK[1]+$work_hours_BRK[1];
								//echo "<br>".$total_min;
								$total_work_hrs_in_month=$total_hours.":".$total_min;
								$quotient=$total_min/60;
								//echo "<br>".$quotient;
								$q=explode(".",$quotient);
								//echo "<br>".$q[0];
								if($q[0]!=0)
								{$r=$totalMin%60;}
								else
								{$r=$total_min;}
								$finalWorkHours=($total_hours+$q[0]).":".$r;
							}	
						}
						else {$finalWorkHours='';}
					}
					
				}
				//echo $TotalOt."<br>";
				//echo "final===".$finalWorkHours."<br>";
				$TotalOt_BRK=explode(':',$TotalOt);
				$finalWorkHours_BRK=explode(':',$finalWorkHours);
				
				$hrs=$TotalOt_BRK[0]+$finalWorkHours_BRK[0];
				$min=$TotalOt_BRK[1]+$finalWorkHours_BRK[1];
				
				$quotient=$min/60;
				$q=explode(".",$quotient);
				
				if($q[0]!=0)
				{$r=$min%60;}
				else
				{ $r=$min;}
				$FinalGrandTotalOT=($hrs+$q[0]).":".$r;
				$ot_amt_per_day=round($wages_rate/$days_in_month,2);
				$ot_amt_per_hour=round($ot_amt_per_day/8,2);

				$ot_hours_brk=explode(':',$FinalGrandTotalOT);
				$hours=$ot_hours_brk[0];
				$total_ot_amt_hrs=$hours*$ot_amt_per_hour;
				$minutes=$ot_hours_brk[1];
				$ot_amt_per_min=$ot_amt_per_hour/60;
				$total_ot_amt_min=$minutes*$ot_amt_per_min;
				$ot_grand_total=$total_ot_amt_hrs+$total_ot_amt_min;
			}
			
			else if($emp_status=='Staff')
			{
				$wages_rate=$gross_salary;
				$ot_condition=DB_query("Select OThours from ot_salary_master where emp_shift='".$emp_status_id."'",$db);
				$ot_condition_res=DB_fetch_array($ot_condition);
				
				$check_ot_time="SELECT COUNT(*) as count FROM daily_attendance WHERE ot_hrs>='6:30' AND employee='".$emp_id."' AND MONTH(attendance_date)='0".$month."' and YEAR(attendance_date)='".$years."'";
				$check_res=DB_query($check_ot_time,$db);
				$check_row=DB_fetch_array($check_res);
				//echo $check_row['count'];
				$cr=0;
				for($i=$startdate;$i<=$end_date;$i++)
				{
					
					//echo DayOfDate($i);//==$week_off_day
					//echo $week_off_day;
					if(DayOfDate($i)==$week_off_day)
					{
						$check_week_off_present="Select work_hrs,pres_abs from daily_attendance where attendance_date='".$i."' and employee='".$emp_id."' and pres_abs='P' and work_hrs>='6:30'";
						$check_result=DB_query($check_week_off_present,$db);
						$weekly_off_ot_days=DB_num_rows($check_result);
						if($weekly_off_ot_days==1)
						{$cr++;}
					}
				}
				
				
				if($check_row['count']>0 || $cr>0)
				{
					$FinalGrandTotalOT=$check_row['count']+$cr." Day(s)";
					if($wages_rate>='10000')
					{
						$ot_grand_total=$check_row['count']+$cr." CL";
					}
					else if($wages_rate<'10000')
					{
						$one_day_salary=$wages_rate/$days_in_month;
						$ot_grand_total=(round($one_day_salary)*($check_row['count']+$cr))." (".($check_row['count']+$cr)." day(s) salary)";
					
					}
				}
				else {$FinalGrandTotalOT=''; $ot_grand_total='';}
			}
			
?> 
  <tr class="f11"> 
    <td><?php echo $emp_name;?></td>
	<td><?php echo $emp_code;?></td>
    <td><?php echo $FinalGrandTotalOT;?></td>
	<td><?php echo $wages_rate;?></td>
    <td><?php if($emp_status=='Worker'){echo round($ot_grand_total);}else echo $ot_grand_total;?></td>
	<td>&nbsp;</td>
   </tr>
 <?php } ?>  
 </tbody>
 </table>
 
</div>

</div>

</body>
</html>
 