<?
 session_start();
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); parent.document.location='ind.php' </script>";
  return;
}

 include("test.php");
include("opendb.php");
?>
<style>
td{font-family:arial;font-size:13}
body{background-color:white}
</style>
<center>

<font face='arial black'>
<?print $branch?><br>
Opening Trial Balance
</font>[Printed by <?print $user?>]
<table border=1>
<TR bgcolor='#5b5858'><TD COLSPAN=3 ALIGN=CENTER><font color=white>
<b>TRIAL BALANCE AS ON <?print date("d-M-Y",time())?> </TD></TR>
<tr><td>&nbsp;</td><td align=center><b>Debit</td><td align=center><b>Credit</td></tr>
<?

 $result=mysqli_query($db,"select distinct grp from ledger where brcode='$brcode'")or die(mysqli_error());
while($row=mysqli_fetch_row($result))
  { 
$tr=0;$tp=0;$bal=0;
        print "\n<tr><td colspan=3><b><font color='brown'>$row[0]</td></tr>";
   $sqq="select * from ledger where brcode='$brcode' and grp='$row[0]'";
//  print "<br>". $sqq;
     $re=mysqli_query($db,$sqq) or die(mysqli_error());
     while($row2=mysqli_fetch_array($re))
     {
//print "<br>- ".$row2[0];
	if($row2[drcr]=="Dr")
	{
		if($row2[op]!=0)
       print "<tr><td> <blockquote> $row2[led]</td><td align=right>$row2[op]</td></tr>";
        $t1+=$row2[op];
	}
	else 
	{
//	$tp+=$row2[op];
		if($row2[op]!=0)
       print "<tr><td> <blockquote> $row2[led]</td><td></td><td align=right>$row2[op]</td></tr>";
        $t2+=$row2[op];
	}
 }
}
$rs=mysqli_query($db,"select opstock from plopstock");
$vv=mysqli_fetch_array($rs);
$t1+=$vv[0];
print "<tr><td><font color=brown><b>Opening Stock</td><td>".putComa($vv[0])."</td></tr>";
print "<tr><td>&nbsp;</td><td>".putComa($t1)."</td><td>".putComa($t2)."</td></tr>";
$diff22=($t1-$t2);
$diff22=number_format($diff22,2,'','');
?>
</table>
<?
print "Opening Contra=".putcoma(abs($diff22));
?>
