<?
session_start();
include("opendb.php");
include("test.php");
?>
<title>PSN Telcon</title>
<script type="text/javascript" src="scripts/jquery-latest.js"></script>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link rel="stylesheet" href="css/form.css" type="text/css" />
<script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>

<body background="back_ground.jpg">
<?php include('logo2.php'); ?>
<?php include('includes/top.php'); ?>

<script>
 function serv(a,b)
 {
   document.location='serv.php?code='+a+'&tp='+b;
 }
 function sms(a,b)
 {
   window.open('sendsms.php?code='+a+'&tp='+b);
 }

</script>

<br>
<table class="container"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Master >> <a href="mach_menu.php" style="text-decoration:none;">Machine</a> >> Service Report</font>
<br>
<center>

<form action='<?print $PHP_SELF?>' method='post'>
<table bgcolor=aliceblue class='form'>
<tr bgcolor='green'><th colspan='4'><font color='white'>SERVICE REPORT</font></th></tr>
<tr><td>From </td><td>DD <input type=text name=d1 size=2 value='<?print date("d")?>'></td>
		<td>MM <input type=text name=m1 size=2 value='<?print date("m")?>'></td>
		<td>YY <input type=text name=y1 size=4 value='<?print date("Y")?>'></td>
</tr>

<tr><td>To </td><td>DD <input type=text name=d2 size=2 value='<?print date("d")?>'></td>
		<td>MM <input type=text name=m2 size=2 value='<?print date("m")?>'></td>
		<td>YY <input type=text name=y2 size=4 value='<?print date("Y")?>'></td>
</tr>
<tr><td colspan=4 align=center><input type=radio name='chk' value='m' checked>by Month/date
			       <input type=radio name='chk' value='h' >by Hour </td>
</tr>
<tr ><td colspan=4 align=center><input type=submit name='show' value='Show'></td></tr>
</table>
</form>

<?
if($show)
{
 $df=$y1.'-'.$m1.'-'.$d1;
 $dt=$y2.'-'.$m2.'-'.$d2;
PRINT "Service Report by Search from ".datetohtml($df)." to ".datetohtml($dt);
}
else
{
 $df=date("Y-m-d");
 $dt=date("Y-m-d");
PRINT "service Report from ".datetohtml($df)." to ".datetohtml($dt);
}
?>
</center>
<br>
<input type=button value='Send SMS to all' onClick=alert("Under&nbsp;construction")>
<center>
<?
 if($chk=='m')
  {
   $sql="select * from mdet where (s0d>='$df' and s0d<='$dt')";
 $re=mysqli_query($db,$sql) or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
 {
 print "<table border=1 width=100% class='report'> <tr><td colspan=16 align=center ><b><font size=3> S0</td></tr>";
 PRINT "<th>Serv <th>SMS<th>No <th>MCSNO <TH>MACHINE MODEL  <TH>ENGINE NO <TH>ENGINE MODEL <TH>HMR<th>COM DATE<th>SERV DATE <th>ENGINEER <th>BRANCH<TH> CUSTOMER";
 print "<th>DIST <TH>PHONE <TH>MOBILE";
 $i=1;
 while($row=mysqli_fetch_array($re))
 {
   $ss=mysqli_query($db,"select * from customer where code='$row[cname]'");
   $crow=mysqli_fetch_array($ss);

   $modres=mysqli_query($db,"select maname from machmaster where code='$row[model1]'");
   $modrow=mysqli_fetch_array($modres);

      $servres=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s0'");
  if(mysqli_num_rows($servres)<=0)
   {
     print "<tr onMouseOver=bgColor='bed2b0'; onMouseOut=bgColor='white'><td><input type=button value='S' onClick=javascript:serv('$row[code]','s0')> 
</td><td bgcolor='aliceblue'><center><input type=checkbox name=sm[] checked>
<input type=button value='sms' onClick=javascript:sms('$row[code]','s0')></td>";
     $srv=1;
   }
  else
   {
      print "<tr><td bgcolor=adf171>&nbsp;</td><td></td>";  
	      $servrow=mysqli_fetch_array($servres);
	$ss=mysqli_query($db,"select * from customer where code='$servrow[customer]'");
   $crow=mysqli_fetch_array($ss);

  }
 $engnr=getengnr($row[mcsno]);
 $branch=getbr($row[mcsno]);
print "<td align=center>".$i++."</td><td>$row[0]</td><td><center>$modrow[0]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>".datetohtml($row[dcomm])."</td><td>".datetohtml($row[s0d])."</td>";
print "<td>$engnr</td><td>$branch</td><td>$crow[cname]</td><td>$crow[dist1]</td><td>$crow[phone1]</td><td>$crow[mob]</td></tr>";
 }
 print "</table>";

 }
//************1
   $sql="select * from mdet where (s1m>='$df' and s1m<='$dt') ";

 $re=mysqli_query($db,$sql) or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
 {
 print "<table border=1 width=100% class='report'><tr><td colspan=16 align=center > S1</td></tr>";
 PRINT "<th>Serv <th>SMS<th>No <th>MCSNO <TH>MACHINE MODEL  <TH>ENGINE NO <TH>ENGINE MODEL <TH>HMR<th>COM DATE<th>SERV DATE <th>ENGINEER <th>BRANCH<TH> CUSTOMER";
 print "<th>DIST <TH>PHONE <TH>MOBILE";
 $i=1;
 while($row=mysqli_fetch_array($re))
 {
   $ss=mysqli_query($db,"select * from customer where code='$row[cname]'");
   $crow=mysqli_fetch_array($ss);

   $modres=mysqli_query($db,"select maname from machmaster where code='$row[model1]'");
   $modrow=mysqli_fetch_array($modres);

$sqq="select * from servdet where code='$row[code]' and serviceno='s1'";

      $servres=mysqli_query($db,$sqq);
  if(mysqli_num_rows($servres)<=0)
   {
      $servs0=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s0'");
      if(mysqli_num_rows($servs0)>0)
       print "<tr><td><input type=button value='S' onClick=javascript:serv('$row[code]','s1')>
</td><td><center><input type=checkbox name=sm[] checked>
 <input type=button value='sms' onClick=javascript:sms('$row[code]','s1')></td>"; 
       else
        continue;
   }
    else
   {
      print "<tr><td bgcolor=adf171>&nbsp;</td><td></td>";  
	      $servrow=mysqli_fetch_array($servres);
	$ss=mysqli_query($db,"select * from customer where code='$servrow[customer]'");
   $crow=mysqli_fetch_array($ss);
  }

   print "<td align=center>".$i++."</td><td>$row[0]</td><td><center>$modrow[0]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>".datetohtml($row[dcomm])."</td><td>".datetohtml($row[s0d])."</td>";
print "<td>$engnr</td><td>$branch</td><td>$crow[cname]</td><td>$crow[dist1]</td><td>$crow[phone1]</td><td>$crow[mob]</td></tr>";
 }
 print "</table>";
 }
//************2


   $sql="select * from mdet where (s2m>='$df' and s2m<='$dt') ";

 $re=mysqli_query($db,$sql) or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
 {
 print "<table border=1 width=100% class='report'><tr><td colspan=16 align=center class='report'> S2</td></tr>";
 PRINT "<th>Serv <th>SMS<th>No <th>MCSNO <TH>MACHINE MODEL  <TH>ENGINE NO <TH>ENGINE MODEL <TH>HMR<th>COM DATE<th>SERV DATE <th>ENGINEER <th>BRANCH<TH> CUSTOMER";
 print "<th>DIST <TH>PHONE <TH>MOBILE";
$i=1;
 while($row=mysqli_fetch_array($re))
 {
  $ss=mysqli_query($db,"select * from customer where code='$row[cname]'");
   $crow=mysqli_fetch_array($ss);


      $servres=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s2'");
  if(mysqli_num_rows($servres)<=0)
      {
      $servs0=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s1'");
      if(mysqli_num_rows($servs0)>0)
       print "<tr><td><input type=button value='S' onClick=javascript:serv('$row[code]','s2')>
<input type=checkbox name=sm[] checked></td><td>
 <input type=button value='sms' onClick=javascript:sms('$row[code]','s2')></td>"; 
       else
        continue;
   }
    else
   {
      print "<tr><td bgcolor=adf171>&nbsp;</td>";  
	      $servrow=mysqli_fetch_array($servres);
	$ss=mysqli_query($db,"select * from customer where code='$servrow[customer]'");
   $crow=mysqli_fetch_array($ss);
  }


   print "<td align=center>".$i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>".datetohtml($row[dcomm])."</td><td>".datetohtml($row[s2m])."</td><td>$crow[cname]</td><td>$crow[dist1]</td><td>$crow[phone1]</td><td>$crow[mob]</td></tr>";
 }
 print "</table>";
 }
//************3
   $sql="select * from mdet where (s3m>='$df' and s3m<='$dt')";

 $re=mysqli_query($db,$sql) or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
 {
 print "<table border=1 width=100% class='report'><tr><td colspan=16 align=center bgcolor=lightsteelblue> S3</td></tr>";
 PRINT "<th>Serv <th>SMS<th>No <th>MCSNO <TH>MACHINE MODEL  <TH>ENGINE NO <TH>ENGINE MODEL <TH>HMR<th>COM DATE<th>SERV DATE <th>ENGINEER <th>BRANCH<TH> CUSTOMER";
 print "<th>DIST <TH>PHONE <TH>MOBILE";
 $i=1;
 while($row=mysqli_fetch_array($re))
 {
  $ss=mysqli_query($db,"select * from customer where code='$row[cname]'");
   $crow=mysqli_fetch_array($ss);


      $servres=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s3'");
  if(mysqli_num_rows($servres)<=0)
   {
      $servs0=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s2'");
      if(mysqli_num_rows($servs0)>0)
       print "<tr><td><input type=button value='S' onClick=javascript:serv('$row[code]','s3')> <input type=button value='sms' onClick=javascript:sms('$row[code]','s3')></td>"; 
       else
        continue;
   }
    else
   {
      print "<tr><td bgcolor=adf171>&nbsp;</td>";  
      $servrow=mysqli_fetch_array($servres);
	$ss=mysqli_query($db,"select * from customer where code='$servrow[customer]'")or die(mysqli_error($db));
   $crow=mysqli_fetch_array($ss);
  }

   print "<td align=center>".$i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>".datetohtml($row[dcomm])."</td><td>".datetohtml($row[s3m])."</td><td>$crow[cname]</td><td>$crow[dist1]</td><td>$crow[phone1]</td><td>$crow[mob]</td></tr>";
 }
 print "</table>";
 }

//************4
   $sql="select * from mdet where (s4m>='$df' and s4m<='$dt')";

 $re=mysqli_query($db,$sql) or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
 {
 print "<table border=1 width=100% class='report'><tr><td colspan=16 align=center > S4</td></tr>";
 PRINT "<th>Serv <th>SMS<th>No <th>MCSNO <TH>MACHINE MODEL  <TH>ENGINE NO <TH>ENGINE MODEL <TH>HMR<th>COM DATE<th>SERV DATE <th>ENGINEER <th>BRANCH<TH> CUSTOMER";
 print "<th>DIST <TH>PHONE <TH>MOBILE";
 $i=1;
 while($row=mysqli_fetch_array($re))
 {
  $ss=mysqli_query($db,"select * from customer where code='$row[cname]'");
   $crow=mysqli_fetch_array($ss);


      $servres=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s4'");
  if(mysqli_num_rows($servres)<=0)
   {
      $servs0=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s3'");
      if(mysqli_num_rows($servs0)>0)
       {
	print "<tr><td><input type=button value='S' onClick=javascript:serv('$row[code]','s4')>";
        print "<input type=button value='sms' onClick=javascript:sms('$row[code]','s4')></td>"; 
       }
       else
        continue;
   }
    else
   {
      print "<tr><td bgcolor=adf171>&nbsp;</td>"; 
	      $servrow=mysqli_fetch_array($servres); 
	$ss=mysqli_query($db,"select * from customer where code='$servrow[customer]'");
   $crow=mysqli_fetch_array($ss);
  }


   print "<td align=center>".$i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>".datetohtml($row[dcomm])."</td><td>".datetohtml($row[s4m])."</td><td>$crow[cname]</td><td>$crow[dist1]</td><td>$crow[phone1]</td><td>$crow[mob]</td></tr>";
 }
 print "</table>";
 }


//****************************** 5
//************4
   $sql="select * from mdet where (s5m>='$df' and s5m<='$dt')";

 $re=mysqli_query($db,$sql) or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
 {
 print "<table border=1 width=100% class='report'><tr><td colspan=16 align=center > S5</td></tr>";
 PRINT "<th>Serv <th>SMS<th>No <th>MCSNO <TH>MACHINE MODEL  <TH>ENGINE NO <TH>ENGINE MODEL <TH>HMR<th>COM DATE<th>SERV DATE <th>ENGINEER <th>BRANCH<TH> CUSTOMER";
 print "<th>DIST <TH>PHONE <TH>MOBILE";
 $i=1;
 while($row=mysqli_fetch_array($re))
 {
  $ss=mysqli_query($db,"select * from customer where code='$row[cname]'");
   $crow=mysqli_fetch_array($ss);


      $servres=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s5'");
  if(mysqli_num_rows($servres)<=0)
   {
      $servs0=mysqli_query($db,"select * from servdet where code='$row[code]' and serviceno='s4'");
      if(mysqli_num_rows($servs0)>0)
       print "<tr><td><input type=button value='S' onClick=javascript:serv('$row[code]','s5')> <input type=button value='sms' onClick=javascript:sms('$row[code]','s5')></td>"; 
       else
        continue;
   }
    else
   {
      print "<tr><td bgcolor=adf171>&nbsp;</td>"; 
	      $servrow=mysqli_fetch_array($servres); 
	$ss=mysqli_query($db,"select * from customer where code='$servrow[customer]'");
   $crow=mysqli_fetch_array($ss);
  }


   print "<td align=center>".$i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>".datetohtml($row[dcomm])."</td><td>".datetohtml($row[s4m])."</td><td>$crow[cname]</td><td>$crow[dist1]</td><td>$crow[phone1]</td><td>$crow[mob]</td></tr>";
 }
 print "</table>";
 }
 } // end if chk
//}
function getengnr($ecode)
{
$sq="select engineer from minput where msno='$ecode'";
  $re=mysqli_query($db,$sq);
  $enrow=mysqli_fetch_row($re);
 $en_res=mysqli_query($db,"select empname from empmaster where empcode='$enrow[0]'");
  $en_row=mysqli_fetch_row($en_res);
  return $en_row[0];
}
function getbr($ecode)
{
$sq="select brcode from minput where msno='$ecode'";
  $re=mysqli_query($db,$sq);
  $enrow=mysqli_fetch_row($re);
 $en_res=mysqli_query($db,"select brname from branch where brcode='$enrow[0]'");
  $en_row=mysqli_fetch_row($en_res);
  if(strlen($en_row[0])>0)
   return $en_row[0];
  else
   return '-';
}

?>
<br>&nbsp;

</td></tr></table>
