<link href="css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<html>
<body >

<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='index.html'; </script>";
 return;
}

include("opendb.php");
include("test.php");

?>
<script>
 function validtime(x)
 {
  var na=document.getElementById(x).value;
  if(na=='00')
   {
     alert("Invalid Time, Use 24 hour time format");
    document.getElementById(x).value='00';
    document.getElementById(x).focus();
    return false;
   }
  if(na.length<2 && na<6 ||na>=60)
   {
     alert("Invalid Time, Use 24 hour time format");
    document.getElementById(x).value='00';
    document.getElementById(x).focus();
    return false;
   }

 }
 function validmin(x)
 {
  var na=document.getElementById(x).value;
  if(na.length<2 ||na>=60)
   {
     alert("Invalid Minute, Use 24 hour time format");
    document.getElementById(x).value='00';
    document.getElementById(x).focus();
    return false;
   }

 }
</script>

<?
if($sv)
{

$phead=getphead($user,$model);
$dhead=getdhead($user,$model);

$inqdate=date("Y-m-d");
if(!checkdate($m2,$d2,$y2))
{
 print "<script>alert('Invalid Nxt Obj. Date'); history.back(1);</script>";
 return;
}
if(strlen($plat)<=1)
{
 print "<script> alert('Invalid platform') </script>";
 return;
}
$nxtobjdt=$y2.'-'.$m2.'-'.$d2;

$tfrom=$tfromh.":".$tfromm;
$tto=$ttoh.":".$ttom;
$followdate=$fy.'-'.$fm.'-'.$fd;
if($level<1)
{
$sq="select to_days(curdate())-to_days('$followdate')";
$dtre=mysqli_query($db,$sq)or die(mysqli_error());
$dtrow=mysqli_fetch_row($dtre);

if($dtrow[0]>2)
{
 print "<script> alert('Invalid Date, Entry too old'); history.back(1); </script>";
 return;
}
}
//**********
if($level<1)
{

$sq="select to_days('$followdate')-to_days('$nxtobjdt')";
$dtre1=mysqli_query($db,$sq)or die(mysqli_error());
$dtrow=mysqli_fetch_row($dtre1);
if($dtrow[0]>=0)
{
 print "<script> alert('Invalid Next followup Date'); history.back(1); </script>";
 return;
}
}
//*********
include("presale/validtime.php");
$vd=validate($followdate,$tfrom,$tto,$user);
if($vd=='y')
{
 print "<script> alert('Time has already been used'); history.back(1)</script>";
 return;
}
$ondate=date("Y-m-d H:i:s");





 $sql="insert into followup (inqno, user, brcode, vobj, rmrk, platf, platcrite, nxtobj, nxtobjdt, discus,date,prospect,executive,atake,tfrom,tto,followdate,ondate,dhead,phead,model,rate,ussage,tonnage,oformno) values('$inqno', '$user','$brcode',  '$vobj', '$rmrk', '$plat','$refby', 'followup', '$nxtobjdt','$discus','$inqdate','$prospect', '$user1','$atake','$tfrom','$tto','$followdate','$ondate','$dhead','$phead','$model','$rate','$ussage','$tonnage','$oformno')";
mysqli_query($db,$sql) or die('Follow:'.mysqli_error());
mysqli_query($db,"update followup set done='y' where code='$code' and prospect='$prospect'");


}

?>
<head>
<script>

var s=[];
function valid()
{
 if(document.f1.plat.value.length<=1)
  {
    alert('Warning:Invalid Platform');
    return false;
  }
  if(document.f1.tfromh.selectedIndex==0)
   {
     alert("Invalid Time, Use 24 hour time format");
    document.f1.tfromh.value='00';
    document.f1.tfromh.focus();
    return false;
   }
  if(document.f1.ttoh.selectedIndex==0)
   {
     alert("Invalid Time, Use 24 hour time format");
    document.f1.ttoh.value='00';
    document.f1.ttoh.focus();
    return false;
   }
  if(document.f1.ttoh.selectedIndex<document.f1.tfromh.selectedIndex)
   {
     alert("Invalid from, to Time");
    document.f1.ttoh.value='00';
    document.f1.ttoh.focus();
    return false;
   }
  if(confirm('Date and time is very important, check date and time \n Other wise data will be lost \nPress OK to save'))
    return true;
  else
    return false;
}
</script>
</head>
<form name="f1" method='post' action='<?print $PHP_SELF?>' onSubmit="return valid()">
<input type=hidden name='prospect' value='<?print $pros?>'>
<input type=hidden name='code' value='<?print $code?>'>

<?

$inqres=mysqli_query($db,"select * from inquiry where prospect='$pros' and brcode='$brcode' and inqno='$inq'");
$inqrow=mysqli_fetch_array($inqres);

$inqres1=mysqli_query($db,"select * from followup where  brcode='$brcode' and inqno='$inq' order by code desc limit 1");
$inqrow1=mysqli_fetch_array($inqres1);

$pl=$inqrow1[platf];


print "<input type=hidden name='user1' value='$inqrow[exec]'>";
?>
    <center>
  <table border="0" cellpadding="2" cellspacing="1" bgcolor='#B0C4DE' width="675">
    <tr>
      <td colspan="9" align="center" width="643" height="17" bgcolor="steelblue">
<font color=white>F O L L O W U P&nbsp;&nbsp; D E&nbsp; T A I L S&nbsp;</td>
    </tr>
    <tr>
      <td height="27" width="120" colspan="2">Inquiry No</td>
      <td height="27" width="161" align="left" colspan="3">
<input type=text name='inqno' size="5" readonly value='<?print $inqrow[inqno]?>'>
      </td>

      <td height="27" width="129" colspan="2">
        <p align="left">Followup Date</td>

      <td height="27" >
	dd <input type=text name='fd' size=2 value='<?print date('d')?>'>
	mm <input type=text name='fm' size=2 value='<?print date('m')?>'>
	yy <input type=text name='fy' size=4 value='<?print date('Y')?>'>

      </td>
    </tr>

    <tr>
      <td height="25" width="120" colspan="2">inquiry Source</td>
      <td height="25" width="161" align="left" colspan="3">
 	<?print $inqrow[isource]?>
</td>
      <td height="25" width="147" colspan="2">Referred to</td>
      <td height="25" width="128" align="left" colspan="2"> <input type=text readonly name='refby' size="15" value=<? print $inqrow[refby]?>
      </td>
    </tr>
    <tr>
      <td height="27" width="120" colspan="2">Prospect</td>
      <td height="27" width="161" align="left" colspan="3"> 
<?
$pres=mysqli_query($db,"select pcode,pname from prospmaster where pcode='$inqrow[prospect]'");
$prow=mysqli_fetch_array($pres);
 print "$prow[1]";

?>


      </td>
      <td height="27" width="147" colspan="2">Attended By</td>
      <td height="27" width="128" align="left" colspan="2">
<?
$empres=mysqli_query($db,"select empcode,empname from empmaster where empcode='$inqrow[user]' ");
$emprow=mysqli_fetch_row($empres);
 print "$emprow[1]";
?>

      </td>
    </tr>
    <tr>
      <td height="27" width="120" colspan="2">Vehicle Model</td>
      <td height="27" width="161" align="left" colspan="3"><input type=text readonly name='model' size="15" value=<? print "'$inqrow[model]'" ?>

      </td>

    </center>
      <td height="27" width="129" colspan="2">
        <p align="left">Rate</td>
    <center>

      <td height="27" width="146" colspan="2">
        <?print $inqrow[rate]?>
      </td>
    </tr>

    <tr>
      <td height="27" width="120" colspan="2">Usage</td>
      <td height="27" width="161" align="left" colspan="3"><input type=text readonly name='ussage' size="15" value=<? print "'$inqrow[ussage]'" ?> </td>

    </center>
      <td height="27" width="129" colspan="2">
        <p align="left">Tonnage</td>
    <center>

      <td height="27" width="146" colspan="2">
<input type=text readonly name='tonnage' size="15" value=<? print "'$inqrow[tonnage]'"?>
      </td>
    </tr>
    
</table>
<br>
<?/******************************/?>

<table border=1>
<tr><td valign=top>
<table border="0" cellpadding="2" cellspacing="1" bgcolor='#B0C4DE'>
    <tr>
      <td  height=25  colspan="9" bgcolor="steelblue">
        <p align="center"><font color=white>O T H E R &nbsp; D E T A I L S</td>
    </tr>
    <tr bgcolor='lightsteelblue'>
      <td  align=center>Visit objective</td>
      <td   align=center>Remark
      </td> </TR>

<tr>
<td align=center>
<input type=text name ='vobj'>
</td><td colspan=2><center><input type=text name='rmrk'></td>
</tr>
 <tr>
      <td  align=center>Time Spent 
      </td>
 	<td>From Hr <select name='tfromh'>
        <option>00</option>
	<option>6</option>
	<option>7</option>
	<option>8</option>
	<option>9</option>
	<option>10</option>
	<option>11</option>
	<option>12</option>
	<option>13</option>
	<option>14</option>
	<option>15</option>
	<option>16</option>
	<option>17</option>
	<option>18</option>
	<option>19</option>
	<option>20</option>
	<option>21</option>
	<option>22</option>
	<option>23</option>
   </select>

 Min<select name='tfromm'>
<option>00</option>
<option>5</option>
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
<option>40</option>
<option>45</option>
<option>50</option>
<option>55</option>
</select>
  <br>
            To &nbsp; &nbsp;Hr <select name='ttoh' id='tto'>
	<option>00</option>
	<option>6</option>
	<option>7</option>
	<option>8</option>
	<option>9</option>
	<option>10</option>
	<option>11</option>
	<option>12</option>
	<option>13</option>
	<option>14</option>
	<option>15</option>
	<option>16</option>
	<option>17</option>
	<option>18</option>
	<option>19</option>
	<option>20</option>
	<option>21</option>
	<option>22</option>
	<option>23</option>
   </select>

 Min <select name='ttom'>
<option>00</option>
<option>5</option>
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
<option>40</option>
<option>45</option>
<option>50</option>
<option>55</option>
</select>

     </tr>    
<tr>
    <tr>
      <td height="41"> Discussion</td>
	<td colspan=2><textarea name='discus' cols=39><?print $discus?></textarea></td>
    </tr>
    <tr>
      <td height="41"> Action to take</td>
	<td colspan=2><textarea name='atake' cols=39><?print $atake?></textarea></td>
    </tr>

<td>
Next objective </td><td colspan=3>
<input type=text name ='nxtobj' size=40>
</td>
</tr>
    <tr>
      <td height="41">Next Visit Date</td>
	<td colspan=2>  
	dd <input type=text name='d2' size="2" >
        mm <input type=text name='m2' size="2" value='<?print date('m')?>'>
        yy <input type=text name='y2' size="4" value='<?print date('Y')?>'></td>
    </tr>

   <tr>
      <td height="41">Online Order form No.</td>
	<td colspan=2>  
	 <input type=text name='oformno' size="10" value=<? print "'$inqrow1[oformno]'"?>>
       
    </tr>
    

<tr><td colspan=4 bgcolor='steelblue' align=center><input type=submit value='Save' name='sv'></td></tr>
  </table>
</td>
<td valign=top>
 <table>
 <tr><td colspan=2 align=center BGCOLOR='LIGHTSTEELBLUE'>ACTION TAKEN</td></tr>
 <?
  $platres=mysqli_query($db,"select * from pcmaster order by val");
  while($platrow=mysqli_fetch_array($platres))
  {
   if($platrow[plat]=='S1')
   print "\n<tr bgColor='#FFE0A5'>";
   if($platrow[plat]=='S2')
   print "\n<tr bgColor='#CAB183'>";
   if($platrow[plat]=='S3')
   print "\n<tr bgColor='silver'>";
   if($platrow[plat]=='S4')
   print "\n<tr bgColor='pink'>";
   if($platrow[plat]=='S5')
   print "\n<tr bgColor='#E08B98'>";


   print "<td><input type=checkbox name=ch[] value='$platrow[val]' onChange='getplat(this,this.value)'></td>";
   print "<td>$platrow[criteria]</td></tr>";
  }
 ?>
 </table>
</td></tr>
</table>

<?

$inqres11=mysqli_query($db,"select * from followup where inqno='$inq' and brcode='$brcode' order by date desc limit 1")or die(mysqli_error());

$inq_row=mysqli_fetch_array($inqres11);
?>
Platform Value: <input type=text readonly name='platf' value='0'>

Platform  <input type=text name='plat' readonly value='<?print $pl ?>'>

    </center>
  </div>
</form>
<?
 $sumres=mysqli_query($db,"select distinct plat,sum(val) from pcmaster  group by plat order by val");
   $k=0;
while($sumrow=mysqli_fetch_row($sumres))
{
 print "\n<script>s[$k]=$sumrow[1]</script>";
 $k++;
}
?>
<script>

 function getplat(y,x)
 {
  if(y.checked)
   document.f1.platf.value=parseInt(document.f1.platf.value)+parseInt(x);
  else
   document.f1.platf.value=parseInt(document.f1.platf.value)-parseInt(x);
 var val=parseInt(document.f1.platf.value);

 if(val>=(s[4]+s[3]+s[2]+s[0]+s[1]))
  document.f1.plat.value='S5';
 else if(val>=(s[3]+s[2]+s[0]+s[1]))
  document.f1.plat.value='S4';
 else if(val>=(s[2]+s[0]+s[1]))
  document.f1.plat.value='S3';
 else if(val>=(s[1]+s[0]))
  document.f1.plat.value='S2';
 else if(val>=s[0])
  document.f1.plat.value='S1';
 else
   document.f1.plat.value=''

 }
</script>


<hr>
<table border=0 cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<centre>
<th class=list>No<th class=list>Objective<th class=list>Remark<th class=list>Platf
<th class=list>Next Obj<th class=list>Nxt Obj Dt<th class=list>Discussion<th class=list>Date
<th class=list>Action taken
<?
$inqres1=mysqli_query($db,"select * from followup where prospect='$pros' and brcode='$brcode' order by date")or die(mysqli_error());
$i=1;
while($inqrow=mysqli_fetch_array($inqres1))
{
 print "<tr bgcolor='white'><td  class=list>$i</td><td  class=list>$inqrow[vobj]</td><td class=list>$inqrow[rmrk]</td><td class=list>$inqrow[platf]</td>";
 print "<td class=list>$inqrow[nxtobj]</td><td class=list>$inqrow[nxtobjdt]</td><td class=list>$inqrow[discus]</td>";
 print "<td class=list>$inqrow[date]</td><td class=list>$inqrow[atake]</td></tr>";
 $i++;
}
print "</table>";

?>
