<?
session_start();
include("../opendb.php");
include("../test.php");
?>
<script>
var pc=[];
var pn=[];

function handleKeyUp(maxNumToShow)
{
    var selectObj, textObj, functionListLength;
    var i, searchPattern, numShown;

    // Set references to the form elements
    selectObj = document.forms[0].functionselect;
    textObj = document.forms[0].pcode;

    // Remember the function list length for loop speedup
    functionListLength = pc.length;

    // Set the search pattern depending
/*    if(document.forms[0].functionradio[0].checked == true)
    {
        searchPattern = "^"+textObj.value;
    }
    else
    {
        searchPattern = textObj.value;
    }
*/
        searchPattern = "^"+textObj.value;

    // Create a regulare expression
    re = new RegExp(searchPattern,"gi");
    // Clear the options list
    selectObj.length = 0;

    // Loop through the array and re-add matching options
    numShown = 0;
    for(i = 0; i < functionListLength; i++)
    {
        if(pc[i].search(re) != -1)
        {
            selectObj[numShown] = new Option(pc[i],pc[i]);
            numShown++;
        }
        // Stop when the number to show is reached
        if(numShown == maxNumToShow)
        {
            break;
        }
    }
    // When options list whittled to one, select that entry
    if(selectObj.length == 1)
    {
        selectObj.options[0].selected = true;
    }
}

// this function gets the selected value and loads the appropriate
// php reference page in the display frame
// it can be modified to perform whatever action is needed, or nothing
function handleSelectClick()
{
    document.f1.pname.value=pn[document.f1.functionselect.selectedIndex];
    document.f1.pcode.value=document.f1.functionselect.value;

}

</script>

<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:lightsteelblue;color:black}
tr{background-color:white}
</style>

<center>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="handleSelectClick();return true;">
<table>
<th colspan=4>STOCK REPORT (BRANCH WISE)</th>
<tr><td>Part Code </td><td>
<input type="text" name="pcode" VALUE="<?print $pcode?>">
<input type=checkbox name='vall' value='y'> View all
<!--<input onKeyUp="handleKeyUp(20);" type="text" name="pcode" VALUE="<?print $pcode?>" style="font-size:10pt;width:34ex;">
<br>
<select onClick="handleSelectClick();" name="functionselect" size="2" style="font-size:10pt;width:34ex;">
<?
/* $i=0;
 $re=mysqli_query($db,"select partcode,partname from partmaster order by partcode");
 while($prow=mysqli_fetch_array($re))
 {
  print "\n<option value='$prow[0]'>$prow[0]</option>";
  print "\n<script>pc[$i]='$prow[0]'; pn[$i]='$prow[1]'; </script>";
 $i++;
 }
*/
?>
</select>
</td></tr>
<tr><td>Part Name </td>
    <td><input type=text name='pname' size=32></td></tr>
-->
<th colspan=3><input type=submit value='Search' name='sea'>
</td></tr>


</table>
</form>
<?
if($sea)
{
include("calcsparestock_br.php");
$tbl="sparetmp_br";
if($vall=='y')
$res=mysqli_query($db,"select * from $tbl  order by brcode")or die(mysqli_error());
else
$res=mysqli_query($db,"select * from $tbl where trim(partcode)='$pcode' order by brcode")or die(mysqli_error());
if(mysqli_num_rows($res)<=0)
{
 print "<font color=red>Part could not be found</font>";
 return;
}
print "<h3> Stock report as on ".date("d-m-Y")."</h3>";
print "<table border=1 cellpadding=3>";
print "<th>Part Code <th>Part Name <th>Qty <th>Branch";
while($row=mysqli_fetch_array($res))
{ 
  $brres=mysqli_query($db,"select brname from branch where brcode='$row[3]'");
  $brrow=mysqli_fetch_row($brres);
 print "<tr><td>$row[0]</td><td>$row[1]</td><td align=right>$row[2]</td><td>$brrow[0]</td>";
}
} // end if
?>
