<?
session_start();
$brcode = $_SESSION['brcode'];
$branch = $_SESSION['branch'];
$user   = $_SESSION['user'];
$level   = $_SESSION['level'];
 include("../test.php");
 include ("../opendb.php");

  $sql="select distinct brcode from branch ";
    $brs=mysqli_query($db,$sql) or die('post err'.mysqli_error($db));
    $k=1;
    while($brs1=mysqli_fetch_array($brs))
    {
        
$chkres=mysqli_query($db,"select jvno,date,sum(dramt),sum(cramt),narr from journal2 where brcode='$brs1[0]' and j_type='Spare trans out' group by jvno") or die(mysqli_error($db));
$i=1;
?>
<table border=1>
<?
$mdiff_tot = 0;
while($row=mysqli_fetch_array($chkres))
{
	if (abs($row[2]-$row[3]) > .02)
	{
		if($i==1)
             {
                  print "<font color=red> Following Transactions are not tallying </font> <br>";
		    print "<tr><td>Sl No</td><td>JV No.</td><td>branch</td><td>Date</td><td>Total Dr</td><td>Total Cr</td><td>Difference</td><td>Narration</td></tr>";
              }
              $mdiff = $row[2]-$row[3];
		$mdiff_tot += $mdiff; 
              print "<tr><td>$i</td><td>$row[0]  </td><td>$brs1[0]  </td><td>$row[1]  </td><td>$row[2]</td><td>$row[3]</td><td>$mdiff</td><td>$row[4]</td></tr>";
		$i++;
			$k++;
	}
}
}
print "<tr><td>Total</td><td></td><td></td><td></td><td></td><td>$mdiff_tot</td><td>$k</td></tr>";
?>
