<?
session_start();
include("../opendb.php");
include("../test.php");
if($sv)
{
 $df=$y.'-'.$m.'-'.$d;
 $dt=$y1.'-'.$m1.'-'.$d1;
 $sql="insert into spareprmast values('$partcode','$df','$dt','$ndpcost','$lstprice','$mrp','$discount','$brcode')";
 mysqli_query($db,$sql) or die(mysqli_error());
 print "<font color=green>Data has been saved</font>";
}

?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:steelblue;color:white}
tr{background-color:white}
</style>
<script>
var pna=[];
function getname()
{
 document.f1.prtname.value=pna[document.f1.partcode.selectedIndex];
}
function valid()
{
 if(document.f1.partcode.selectedIndex<=0)
 {
  alert('Invalid partcode '); return false;
 }
 if(document.f1.ndpcost.value.length<=0)
 {
  alert('Invalid NDP Cost '); return false;
 }
 if(document.f1.lstprice.value.length<=0)
 {
  alert('Invalid List Price '); return false;
 }
 if(document.f1.mrp.value.length<=0)
 {
  alert('Invalid MRP '); return false;
 }
 //return true;
}
</script>
<center>

<!-- <form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()"> -->
<table border=0 cellspacing=1 cellpadding=3 bgcolor='steelblue'>
<th colspan=10><h3>SPARE PRICE MASTER </th>

<!--
<tr><td bgcolor='lightsteelblue'>Part Code </td><td><select name='partcode' onChange=getname();><option></option>
<?
$i=1;
$re=mysqli_query($db,"select * from partmaster ");
while($row=mysqli_fetch_array($re))
{
 print "<option>$row[0]</option>";
 print "\n<script> pna[$i]='$row[partname]';</script>";
 $i++;
}
?>
</select></td>
<td>Part Name </td><td><input type=text name='prtname' size=30></td>
</tr>
<tr>
<td bgcolor='lightsteelblue'>Effect From </td><td>dd <input type=text name='d' size=2 maxlength=2>
mm <input type=text name='m' size=2 maxlength=2>
yy <input type=text name='y' size=4 maxlength=4>
</td>

<td bgcolor='lightsteelblue'>Effect To </td><td>dd <input type=text name='d1' size=2 maxlength=2>
mm <input type=text name='m1' size=2 maxlength=2>
yy <input type=text name='y1' size=4 maxlength=4>
</td></tr>
<tr><td bgcolor='lightsteelblue'>NDP Cost </td><td><input type=text name='ndpcost'></td>
<td bgcolor='lightsteelblue'>List/Sell Price </td><td><input type=text name='lstprice'></td></tr>
<tr>
<td bgcolor='lightsteelblue'>MRP </td><td><input type=text name='mrp'></td>
<td bgcolor='lightsteelblue'>Discount </td><td><input type=text name='discount'></td>
<td rowspan=4 colspan=4 align=center  bgcolor='steelblue'><input type=submit value='  Save  ' name='sv'></td>
</tr>
</table>
</form>
-->
<br>
<?
if($sea)
{
 if(strlen($prtname)>0)
 {
   $sql="select a.partcode,a.partname,b.*  from partmaster a,spareprmast b where a.partname like '%$prtname%' and a.partcode=b.partcode and b.brcode='$brcode' group by a.partcode order by a.partcode,b.effectfrom";
}
 $re=mysqli_query($db,$sql) or die(mysqli_error());
 if(mysqli_num_rows($re)<=0)
 {
  print "<center> <font color=red> Record does not exist</font>";
  return;
 }
 print "<table border=0 cellpadding=3 cellspacing=1 bgcolor='lightsteelblue'> <th>Code <th>Name <th>Eff Frm <th>NDP Cost <th>Lst Price <th>MRP";
 print "<th>Disc";
 while($row=mysqli_fetch_array($re))
 {
   print "<tr bgcolor='aliceblue'><td>$row[partcode]</td><td>$row[partname]</td><td>".datetohtml($row[effectfrom])."</td>";
   print "<td>$row[ndpcost]</td><td>$row[lstprice]</td><td>$row[mrp]</td><td>$row[discount]</td>";
   print "</tr>";
 }
}
?>

<form action='<?print $PHP_SELF?>'>
<table cellspacing=1 cellpadding=2 bgcolor='red'>
<tr><td bgcolor=white><center>
<table bgcolor='ivory' border=0>
<tr ><td bgcolor='lightsteelblue'> Group </td><td><select name='grp'>
<option></option>
<?
 $re=mysqli_query($db,"select distinct group1 from partmaster order by group1")or die(mysqli_error());
 while($ro=mysqli_fetch_row($re))
 {
   print "<option>$ro[0]</option>";
 }
?>
</select></td>

<td bgcolor='lightsteelblue'> Sub Group </td><td><select name='subgrp'>
<option></option>
<?
 $re=mysqli_query($db,"select distinct subgroup from partmaster order by 1")or die(mysqli_error());
 while($ro=mysqli_fetch_row($re))
 {
   print "<option>$ro[0]</option>";
 }
?>
</select></td>
<td bgcolor='lightsteelblue'>Prt Name </td><td><input type=text name='prtname1' size=20></td>
<td bgcolor='lightsteelblue'><input type=submit value='Search' name='sea2'></td></tr>
</table>
</td></tr>
</table>
</form>
<br>
<?
if($sea2)
{
 if(strlen($subgrp)>0)
 {
 $sql="select a.partcode,a.partname,b.*  from partmaster a,spareprmast b where a. subgroup='$subgrp' and a.partcode=b.partcode group by a.partcode order by a.partname";
 }
 else if(strlen($prtname1)>0)
{
 $sql="select a.partcode,a.partname,b.*  from partmaster a,spareprmast b where a. partname like'%$prtname1%' and a.partcode=b.partcode group by a.partcode order by a.partname";

}

 $re=mysqli_query($db,$sql) or die(mysqli_error());
 if(mysqli_num_rows($re)<=0)
 {
  print "<center> <font color=red> Record does not exist</font>";
  return;
 }
 print "<table border=0 cellpadding=3 cellspacing=1 bgcolor='lightsteelblue'> <th>Code <th>Name <th>Eff Frm <th>NDP Cost <th>Lst Price <th>MRP";
 print "<th>Disc";
 while($row=mysqli_fetch_array($re))
 {
   print "<tr bgcolor='aliceblue'><td>$row[partcode]</td><td>$row[partname]</td><td>".datetohtml($row[effectfrom])."</td>";
   print "<td align=right>$row[ndpcost]</td><td align=right>$row[lstprice]</td>";
   print "<td align=right>$row[mrp]</td><td align=right>$row[discount]</td>";
   print "</tr>";
 }
}
?>


