<?
session_start();
include("../opendb.php");
include("../test.php");

if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
if($save)
{
$sql="delete from dbnote where dbno='$dbno' and brcode='$brcode'";
mysqli_query($db,$sql);
$sql="delete from journal2 where jvno='$jvno' and brcode='$brcode' and j_type='DB Note'";
mysqli_query($db,$sql);

$dt=$y.'-'.$m.'-'.$d;
 $sql="insert into journal2 values('$dt','$jvno','Dr','$dr','$dramt','0','$drnarr .(DB No.$dbno)','$brcode','DB Note','On Acc',' ','$dbno')";
 mysqli_query($db,$sql)or die(mysqli_error());

 $sql="insert into dbnote (date,dbno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,dbto) values('$dt','$dbno','Dr','$dr','$dramt','0','$drnarr' ,'$brcode','$jvno','On Acc',' ','$dbto')";
 mysqli_query($db,$sql)or die(mysqli_error());

 $sql="insert into journal2 values('$dt','$jvno','Cr','$cr','0','$cramt','$crnarr .(DB No.$dbno)','$brcode','DB Note','On Acc',' ','$dbno')";
mysqli_query($db,$sql) or die(mysqli_error());

 $sql="insert into dbnote (date,dbno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,dbto) values('$dt','$dbno','Cr','$cr','0','$cramt','$crnarr','$brcode','$jvno','On Acc ',' ','$dbto')";
mysqli_query($db,$sql) or die(mysqli_error());

print "<script> alert('Record has been updated');";
print "document.location='shdbnote.php' </script>";
return;
}// end if save
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
 td{font-size:13.5}
</style>
<body bgcolor=ivory>
<table width=100%>
<th>EDIT DEBIT NOTE #<?print $dbno?></th>
</table>
<form action='<?print $PHP_SELF?>' method='post'>
<input type=hidden name='dbno' value='<?print $dbno?>'>

<table>
<?
$res=mysqli_query($db,"select * from dbnote where dbno='$dbno' and brcode='$brcode'");
$ro=mysqli_fetch_array($res);
?>
<input type=hidden name='jvno' value='<?print $ro[j_type]?>'>
<?
$dt=explode('-',$ro[date]);
print "<tr><td>Date</td><td> dd<input type=text name='d' size=2 value='$dt[2]'>".
"mm<input type=text name='m' size=2 value='$dt[1]'>".
"yy<input type=text name='y' size=4 value='$dt[0]'></td></tr>";

print "\n<tr><td>To</td><td> <input type=text name='dbto' size=40 value='$ro[dbto]'></td></tr>";
print "</table><table>";
$res1=mysqli_query($db,"select * from dbnote where dbno='$dbno' and brcode='$brcode' and type='Dr'");
$ro=mysqli_fetch_array($res1);
print "<th>Dr<th>Amount<th>Narr";
print "<tr><td><select name='dr'><option>$ro[partic]</option>";
$ledres=mysqli_query($db,"select * from ledger where brcode='$brcode' order by led");
while($ledrow=mysqli_fetch_array($ledres))
 print "\n<option>$ledrow[led]</option>";
print "</select>";
print "</td><td><input type=text name='dramt' size=8 value='$ro[dramt]'></td>";
print "</td><td><textarea name='drnarr' cols=30>$ro[narr]</textarea></td></tr>";
//*****************
$res2=mysqli_query($db,"select * from dbnote where dbno='$dbno' and brcode='$brcode' and type='Cr'");
$ro=mysqli_fetch_array($res2);

print "<th>Cr<th>Amount<th>Narr";
print "\n<tr><td><select name='cr'><option>$ro[partic]</option>";
$ledres1=mysqli_query($db,"select * from ledger where brcode='$brcode' order by led");
while($ledrow=mysqli_fetch_array($ledres1))
 print "\n<option>$ledrow[led]</option>";
print "</select>";
print "</td><td><input type=text name='cramt' size=8 value='$ro[cramt]'></td>";
print "</td><td><textarea name='crnarr' cols=30>$ro[narr]</textarea></td>";
?>
<tr><td colspan=10 align=center><input type=submit value='Update' name='save'></td></tr>
</table>
</form>

