<? 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)
{
 $entrydate=$y.'-'.$m.'-'.$d;
 $billdate=$y1.'-'.$m1.'-'.$d1;
//mysqli_query($db,"drop table amctrans");

 $sql="create table 55trans (trno int(12),chno varchar(100),amcno varchar (100),entrydate date,billno varchar(100),billdate date, workat varchar(100),partamount double(14,2),lubamount  double(14,2), labamount double(14,2), othamount double(14,2),totamount double(14,2),rem varchar(250),brcode varchar(20))";
 mysqli_query($db,$sql);

$trres=mysqli_query($db,"select max(trno) from 55trans where brcode='$brcode'");
$trrow=mysqli_fetch_row($trres);
if($trrow[0]<=0)
 $trno=1;
else
 $trno=($trrow[0]+1);

 $sql="insert into 55trans values('$trno','$chno','$amcno','$entrydate','$billno','$billdate', '$workat','$partamount','$lubamount', '$labamount', '$othamount','$totamount','$rem','$brcode')";
 mysqli_query($db,$sql);
print "Data has been saved";
}
?>
<script>
function calcamt()
{
totamt=parseFloat(document.f1.partamount.value)+parseFloat(document.f1.lubamount.value)+parseFloat(document.f1.labamount.value)+parseFloat(document.f1.othamount.value);
document.f1.totamount.value=totamt
}
</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:14}
th{background-color:c1d7bb;font-size:14}
.mnu{margin-left:5}
</style>
<center>
<?
$re=mysqli_query($db,"select * from scheme where chno='$chno' and brcode='$brcode' order by entrydate limit 1")or die(mysqli_error());
$row=mysqli_fetch_array($re);
?>
<form name='f1' action='550002.php' method='post'>
<table bgcolor='e0b8da' cellspacing=1 cellpadding=2>
<tr><td colspan=2><center><font size=4>AMC Transaction</td></tr>
<tr bgColor='fdedfb'><td width=150> Chasis </td><td><input type=text readonly name='chno' value='<?print $chno?>'></td></tr>
<tr bgColor='fdedfb'><td width=150> AMC No</td><td><input type=text readonly name='amcno' value='<?print $row[amcno]?>'></td></tr>
<tr bgColor='fdedfb'><td width=150> Amount </td><td><?print $row[amt]?></td></tr>

<tr bgColor='fdedfb'><td>Entry Date </td><td>dd <input type=text name='d' readonly size=2 maxlength=2 value='<?print date('d')?>'>
mm <input type=text name='m'  readonly size=2 maxlength=2 value='<?print date('m')?>'>
yy <input type=text name='y'  readonly size=4 maxlength=4 value='<?print date('Y')?>'>
</td></tr>

<tr bgColor='fdedfb'><td width=150>Bill No</td><td><input type=text name='billno'></td></tr>
<tr bgColor='fdedfb'><td>Bill 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 bgColor='fdedfb'><td>Work done at </td><td>
<select name='workat'>
<?
$brre=mysqli_query($db,"select brname,brcode from br_master  order by brcode");
while($row=mysqli_fetch_row($brre))
{
 print "<option>$row[0]</option>";
}
?>
</select>
</td></tr>
<tr bgColor='fdedfb'><td>Parts Amount</td><td><input type=text name='partamount' value='0' onChange='calcamt()'></td></tr>
<tr bgColor='fdedfb'><td>Lubricant Amount</td><td><input type=text  value='0' name='lubamount' onChange='calcamt()'></td></tr>
<tr bgColor='fdedfb'><td>Labour Amount</td><td><input type=text name='labamount'  value='0' onChange='calcamt()'></td></tr>
<tr bgColor='fdedfb'><td>Other Amount</td><td><input type=text name='othamount' value='0'  onChange='calcamt()'></td></tr>
<tr bgColor='fdedfb'><td>TotalAmount</td><td><input type=text name='totamount' readonly></td></tr>
<tr bgColor='fdedfb'><td>Remark</td><td><textarea name='rem' rows=3 cols=30></textarea></td></tr>
<tr><td colspan=2><center><input type=submit value='Save' name='save'>
<input type=button value='Cancel' onClick=document.location='../blank.html'>
</td></tr>
</table>
</form>
<hr>
<?

print "<table bgcolor='ivory'cellspacing=1 cellpadding=2>";
print "<th>AMC No <th>Entry Date <th>Bill No <th>Bill Dt. <th>Work at <th>Part <th>Lub <th>Labour <th>Other <th>Total <th>Rem";

$res=mysqli_query($db,"select * from 55trans where chno='$chno'")or die(mysqli_error());
while($row=mysqli_fetch_array($res))
{
 print "<tr><td>$row[amcno]</td><td>".datetohtml($row[entrydate])."</td><td>$row[billno]</td><td>".datetohtml($row[billdate])."</td>";
print "<td>$row[workat]</td><td>$row[partamount]</td><td>$row[lubamount]</td>";
print "<td>$row[labamount]</td> <td>$row[othamount]</td><td>$row[totamount]</td>";
print "<td>$row[rem]</td>";
;$q+=$row[totamount];

}
print "<tr><td></td><td align=right colspan=9>Total ".putComa($q)."</td></tr>";
?>

