<?
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($act=='del')
{print 'DB No:'.$code;
 $r=mysqli_query($db,"select j_type from dbnote where dbno='$code' and brcode='$brcode'")or die(mysqli_error());
 $rrow=mysqli_fetch_array($r)or die(mysqli_error());
 $sq="delete from dbnote where dbno='$code' and brcode='$brcode'"; 
 mysqli_query($db,$sq);
 $sq="delete from journal2 where j_type='DB Note' and jvno='$rrow[0]' and brcode='$brcode'"; 
 mysqli_query($db,$sq);
print " - Record has been deleted";
return;
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
 td{font-size:13.5}
</style>
<body bgcolor=ivory>
<p align=center style={background-color:silver;font-size:18}> <b>DEBIT NOTE REPORT</p>
<table border=0 cellspacing=1 cellpadding=2 WIDTH=100%>
<th width=30>DB <th>Date<th>Type <th>Partic <th>Debit <th>Credit <th>Narration <th> Ref. 
<th> No. <th colspan=2>Action
<?
$re=mysqli_query($db,"select distinct dbno,date from dbnote where brcode='$brcode' order by date")or die('Db note err:'.mysqli_error());
while($db_row=mysqli_fetch_array($re))
{
   $rr=mysqli_query($db,"select * from dbnote where dbno='$db_row[0]' and brcode='$brcode'")or die('Db note err:'.mysqli_error());
    print "<tr><td>$db_row[0]</td><td>".datetohtml($db_row[1])."</td><td colspan=7> &nbsp;To:$db_row[dbto]</td>";

print "<td align=center>[<a href='editdbnote.php?dbno=$db_row[0]'>edit</a>]</td><td align=center>[<a href=javascript:del('$db_row[0]')>del</a>]</td></tr>";



   while($row=mysqli_fetch_array($rr))
   {
    print "<tr><td colspan=2><td>$row[2]</td><td>$row[3]</td><td align=right>".nozero($row[4])."</td>";
    print "<td align=right>".nozero($row[5])."</td>";
    print "<td>$row[6]</td><td>$row[9]</td><td>$row[10]</td><td colspan=2></td>";
    
   }
    print "</tr><tr><td colspan=11 bgcolor='gray'></td>";
}
?>
</table>
<script>
function del(x)
{
 if(confirm('Delete DB Note '+x+' ?'))
  document.location='<?print $PHP_SELF?>?act=del&code='+x;
}
</script>

