<html>
<body >

<?
session_start();
include("opendb.php");
include("test.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
?>
<title>Demo</title>

<style type="text/css">
table,tr,td{border-collapse:collapse;padding:1px;border: 1px solid black;}
body{font-family:Verdana;font-size:8px;color:black;}
td{font-family:Verdana;font-size:10px;color:black;height:30px;}
th{font-family:Verdana;font-size:11px;color:black;}
select,input[type=text], textarea{  
background: #eeeeee; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjIzJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, #eeeeee 0%, #ffffff 23%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(23%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* IE10+ */
background: linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#ffffff',GradientType=0 ); /* IE6-8 */
border:1px solid #999; padding:3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;


}
p{padding:0px;}
em{font-size:14px;}
h2{color:#000;font-size:14px;margin:0px;padding:5px 20px;}

</style>
<body onload='window.print();'>



<?



print "<table cellspacing=1 cellpadding=5 width='100%' bgcolor='white' border='1' style='border-collapse:collapse;' width=100%>";
print "<tr ><td align=center colspan='10' ><h2><b><u>".$company."</b> <br>";
?>
<b>Vehicle Released Report:&nbsp;&nbsp;&nbsp;  <? print datetoHtml($fromdt) ?>&nbspto <?print datetoHtml($todt)?> </h2></b></td></tr> 
<?
$df=$fromdt." 00:00:00";
$dt=$todt." 23:59:59";
$qry1=mysqli_query($db,"select * from gateentry where (work_status_date>='$df' and work_status_date<='$dt') and work_status='RELASED' and brcode='$brcode' order by work_status_date,jcno desc");
print  "<tr><th>Sl no<th>Vehicle<th>Regno<th>JobNo.<th>Ins.<th>Inv.Date<th>InvNO.<th>Inv.Amt<th>Released date&time<th>Released By</tr>";
$i=1;

while($row=mysqli_fetch_array($qry1))
{
$qry2=mysqli_query($db,"select * from jcworking_status where  work_status='RELASED' and brcode='$brcode' and jcno='$row[1]' order by update_date desc limit 1");
$row2=mysqli_fetch_array($qry2);

$vehname=getmake($row[1],$brcode);
$insur=getinstype($row[1],$brcode);
$invamt=getinvamt($row[1],$brcode);
$invdate=getinvdate($row[1],$brcode);
$invno=getinvno($row[1],$brcode);


if($row[42]>$row[28]){

 $cr_time=$row[42];
 $pr_time=$row[28];
   $diff1='(+)';
}
else
{

 $pr_time=$row[42];
 $cr_time=$row[28];
 $diff1="<font color='red'>(-)</font>";

}


$t2= convert_datetime($cr_time);
$t1= convert_datetime($pr_time);
$tdiff=time_diff($t1,$t2);

$diff1.=$tdiff;


print "<tr><td>".$i."</td>";
print "<td>$vehname</td><td>$row[4]</td><td>$row[1]</td><td>$insur</td><td align=center>".datetohtml($invdate)."</td><td align=center>$invno</td><td align=right>$invamt</td><td>".dateandtimetoHtml($row[42])."</td><td>$row2[8]</td></tr>";

$i++;

}

print "</table>";



function convert_datetime($str) 
{
	list($date, $time) = explode(' ', $str);
	list($year, $month, $day) = explode('-', $date);
	list($hour, $minute, $second) = explode(':', $time);

	$timestamp = mktime($hour, $minute, $second, $month, $day, $year);

	return $timestamp;
}

function time_diff($t1,$t2)
{
	$difference = $t2-$t1;

	$diffSeconds = $difference;

		//Calculate how many days are within $difference

	$days = intval($difference / 86400); 

		//Keep the remainder

	$difference = $difference % 86400;

		//Calculate how many hours are within $difference	

	$hours = intval($difference / 3600); 

		//Keep the remainder

	$difference = $difference % 3600;

		//Calculate how many minutes are within $difference	

	$minutes = intval($difference / 60); 

		//Keep the remainder

	$difference = $difference % 60;

		//Calculate how many seconds are within $difference	

	$seconds = intval($difference); 

		//Output:
	if($t2==$t1)
	{
	$seconds=20;
	}

	if($days<10)
		$days="0".$days;

	if($hours<10)
		$hours="0".$hours;

	if($minutes<10)
		$minutes="0".$minutes;

	if($seconds<10)
		$seconds="0".$seconds;


	return $days."-".$hours.":".$minutes;
}



?>
