<link href="../css/printline.css" type="text/css" rel="stylesheet" media="print,screen"  />

<?
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");

?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
	tr{background-color:white}
	th{background-color:steelblue;color:white}
</style>
<center>
<form action='<?print $PHP_SELF?>' onSubmit='return valid()'>
<table border=1 width=100%>
</table>
</form>

<br>
<?
$tbl='link'.$brcode;
$sql="create table $tbl (employee varchar(100),ledger varchar(200), empid varchar(20),brcode varchar(100))";

//$sql="create table $tbl (partcode varchar(100),prtname varchar(200), qty double(14,2), price double(14,2), discount double(14,2), hand double(14,2), cst double(14,2), tot double(14,2), brcode varchar(100))";
mysqli_query($db,$sql);


if($add)
{
  $res1=mysqli_query($db,"select * from $tbl where ledger='$ledger'");
  if(mysqli_num_rows($res1)>0)
  {
    print "<script> alert('Duplicate Entry')</script>";
    return;
  }

  $res1=mysqli_query($db,"select * from $tbl where employee='$employee'");
  if(mysqli_num_rows($res1)>0)
  {
    print "<script> alert('Duplicate Entry')</script>";
    return;
  }

  $res1=mysqli_query($db,"select empname from empmaster where empid='$employee'");
  $row1=mysqli_fetch_array($res1);



 $sql="insert into $tbl values('$row1[empname]','$ledger','$employee', '$brcode')";
 mysqli_query($db,$sql);
}

$res=mysqli_query($db,"select * from $tbl order by employee");
if(mysqli_num_rows($res)>0)
{
  $i=1;
  print "<table border=1 cellpadding=3> <th>No <th>Employee <th>Ledger  <th> Del";
  while($row=mysqli_fetch_array($res))
  {
    print "\n<form action='$PHP_SELF'> <input type=hidden name='ledger' value='$row[1]'><tr><td>";
    print $i++."</td><td>$row[0]</td><td>$row[1]</td>";
    print "<td><input type=submit value='Del' name='Del'></td></tr></form>";
  }
 print "</table>";
}

if($View)
{
$res=mysqli_query($db,"select * from $tbl order by employee");
if(mysqli_num_rows($res)>0)
{
  $i=1;
  print "<table border=1 cellpadding=3> <th>No <th>Employee <th>Ledger  <th> Del";
  while($row=mysqli_fetch_array($res))
  {
    print "\n<form action='$PHP_SELF'> <input type=hidden name='ledger' value='$row[1]'><tr><td>";
    print $i++."</td><td>$row[0]</td><td>$row[1]</td>";
    print "<td><input type=submit value='Del' name='Del'></td></tr></form>";
  }
 print "</table>";
}
}

if($Del)
{
 mysqli_query($db,"delete from $tbl where ledger='$ledger'")or die('err'.mysqli_error());
?>
<script>
 document.location='../blank.html';
 window.open('link.html');
</script>
<?
}
?>
<script>
 function valid()
 {
  if(confirm('Do you want to save?'))
   return true;
  else
    return false;
 }
</script>
