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

include("../opendb.php");
include("../test.php");
if($save)
{
$rs=mysqli_query($db,"select max(amcno) from amcmast ");
$cr_row=mysqli_fetch_row($rs);
 if($cr_row[0]<=0)
   $cpno=1;
 else   
   $cpno=$cr_row[0]+1;

 $entrydate=$y.'-'.$m.'-'.$d;
 $dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;
$code=substr($chno,0,4).date("dms");
$sql="create table amcmast (code varchar(100),entrydate date, amcno varchar(100),chno varchar(100),regno varchar(100),config varchar(200) , amt double(14,2),dfrom date,dto date,cust varchar(200),addr varchar(250),brcode varchar(20),rem varchar(250))";
mysqli_query($db,$sql);
$sql="insert into amcmast values('$code','$entrydate','$cpno','$chno','$regno','$config' , '$amt','$dfrom','$dto','$cust','$addr','$brcode','$rem')";
mysqli_query($db,$sql);
print "Record has been saved";
}// end save
?>
<script>
var conf=[];
var cust=[];
var addr=[];
function getconfig()
{
 document.f1.config.value=conf[document.f1.chno.selectedIndex];
 document.f1.cust.value=cust[document.f1.chno.selectedIndex];
 document.f1.addr.value=addr[document.f1.chno.selectedIndex];
}
function valid()
{
 if(document.f1.amt.value<=0 || isNaN(document.f1.amt.value))
 {
  alert("Invalid Amount");
  document.f1.amt.focus();
   return false;
 }
 if(document.f1.cust.value.length<=0 ||document.f1.cust.value=='undefined')
 {
  alert("Invalid Customer or Chasis");
  document.f1.chno.focus();
   return false;
 }
 
 if(confirm('Do you want to save?'))
   return true;
else
  return false;
}
</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d7bb;font-size:13}
.mnu{margin-left:5}
</style>
<center>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()"> 
<table>
<th colspan=4>AMC MASTER</TH>
<tr><td>Entry Date </td><td>dd <input type=text name='d' size=2 maxlength=2 value='<?print date('d')?>'>
mm <input type=text name='m' size=2 maxlength=2 value='<?print date('m')?>'>
yy <input type=text name='y' size=4 maxlength=4 value='<?print date('Y')?>'>
</td></tr>
<tr><td>AMC No </td><td><input type=text readonly name='amcno'></td></tr>
<tr><td>Chasis No </td><td><input type=text name='chno'>
</td></tr>
<tr><td>Reg No </td><td><input type=text name='regno'></td></tr>
<tr><td>Config </td><td><input type=text  name='config' size=30></td></tr>
<tr><td>Amount </td><td><input type=text  name='amt' size=10></td></tr>
<tr><td>From Date </td><td>dd <input type=text name='d1' size=2 maxlength=2 value='<?print date('d')?>'>
mm <input type=text name='m1' size=2 maxlength=2 value='<?print date('m')?>'>
yy <input type=text name='y1' size=4 maxlength=4 value='<?print date('Y')?>'>
</td></tr>
<tr><td>To Date </td><td>dd <input type=text name='d2' size=2 maxlength=2 value='<?print date('d')?>'>
mm <input type=text name='m2' size=2 maxlength=2 value='<?print date('m')?>'>
yy <input type=text name='y2' size=4 maxlength=4 value='<?print date('Y')?>'>
</td></tr>

<tr><td>Customer </td><td><input type=text  name='cust' size=30></td></tr>
<tr><td>Address</td><td><textarea name='addr' rows=3 cols=38 ></textarea></td></tr>
<tr><td>Remark</td><td><textarea name='rem' rows=3 cols=38 ></textarea></td></tr>

<th colspan=4><input type=submit value='Save' name='save'>
<input type=button value='Cancel' onClick=document.location='../blank.html'>
</td></tr>
</table>
</form>
<hr>
<?
$i=1;
print "<table cellspacing=1 cellpadding=3 bgcolor='gray'>";
print "<th>No <th>Entry date <th>AMC No <th>Chasis <th>Reg <th>Config <th>Amount <th>From <th>To";
print "<th>Customer<th>BrCode";
$re=mysqli_query($db,"select * from amcmast order by entrydate");
while($row=mysqli_fetch_array($re))
{
 print "<tr bgcolor='white'><td>".$i++."</td><td>".datetohtml($row[1])."</td> <td>$row[2]</td><td>$row[3]</td>";
 print "<td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>".datetohtml($row[7])."</td><td>".datetohtml($row[8])."</td>";
 print "<td>$row[9]</td><td>$row[brcode]</td>";
}
?>

