<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../../index.html'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");


$sql="select date,jvno,sum(dramt)-sum(cramt),brcode from journal2  where brcode='$brcode' group by jvno,brcode order by brcode";
$re=mysqli_query($db,$sql)or die(mysqli_error($db));
print "<table border=1>";
while($row=mysqli_fetch_array($re))
{
 if($row[2]!=0&&$row[2]<1)//$row[2]<1&&
 {
$dif=$row[2];
$x=abs($dif);
print $dif;
//if($x<0&&$x>1)
if($dif<0)
{
$sql="insert into journal2 values('$row[date]','$row[jvno]','Dr','Round Off','$x', '0','Round of','$row[brcode]','','','','','0','0000-00-00')";
print $sql.'<br>';
mysqli_query($db,$sql) or die("J V Write error dif1:".mysqli_error($db));
}
else if($dif>0 && $dif<1)
{
 $sql="insert into journal2 values('$row[date]','$row[jvno]','Cr','Round Off','0','$x','Round of adjusted','$row[brcode]','','',' ','','0','0000-00-00')";
print $sql.'<br>';
mysqli_query($db,$sql) or die("J V Write error dif:".mysqli_error($db));
}

    print "<tr><td><a href='../multientry/viewtrans.php?code=$row[1]'>$row[0]</a></td><td>$row[1]</td><td>".putComa($row[2])."</td><td>$row[brcode]</td></tr>";
 }
}
print "</table>";
?>
