<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
include_once("includes/function.php");
$us=mysqli_query($db,"select level from bruser where username='$user'")or die(mysqli_error($db));
$r=mysqli_fetch_row($us);
$user_level=$r[0];


if(isset($_POST['save']))
{
    print "ok";
    print $led=$_REQUEST['led'];
        
 if(strlen($led)<=1)
   return;
   
 print $sql="insert into spledgermaster select * from ledger where led='$led'";
 mysqli_query($db,$sql) or die('error:'.mysqli_error($db));
}


if(isset($_POST['del']))
{
    $code=$_REQUEST['code'];
  $sql="delete from spledgermaster where led='$code'";
 mysqli_query($db,$sql) or die(mysqli_error($db));
}
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<script>
function valid()
{
 if(document.f1.config.value.length<=0)
 { alert ('Invalid Configuration'); return false;}
}
</script>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid() "> 
<table cellspacing=1 cellpadding=5 bgcolor=steelblue>
<tr><td align=center colspan=2><font color=white><b>LEDGER MASTER</td> </tr>
<tr bgcolor=white><td>LEDGER </td><td>
<select name='led'>
<?
$re=mysqli_query($db,"select led from ledger  where grp not in ('Sundry Debtors','Sundry Creditors') and brcode='$brcode' order by led ");
while($row=mysqli_fetch_array($re))
{
 print "<option>$row[0]</option>";
}
?>
</select>
</td></tr>
<tr><td colspan=2 align=center><input type=submit value='save' name='save'></td></tr>
</table>


<?
$result=mysqli_query($db,"select * from spledgermaster where brcode='$brcode' order by led");
print "<table cellspacing=1 cellpadding=5 bgcolor='lightsteelblue'>";
print "<th>No <th>Ledger <th>Del";
$i=1;
while($row=mysqli_fetch_row($result))
{
 print "\n<tr bgcolor=white><form action='$PHP_SELF'><input type=hidden name='code' value='$row[0]'><td>".$i++."</td><td>$row[0]</td><td><input type=submit value='Del' name='del'></td></form></tr>";
}
?>
</table>
</form>