<?
 session_start();
$brcode = $_SESSION['brcode'];
$branch = $_SESSION['branch'];
$user   = $_SESSION['user'];
$level   = $_SESSION['level'];

$df=$_REQUEST['df'];
$dt=$_REQUEST['dt'];

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

 include("../test.php");
if($unit=='Mahindra')
{
$db=mysqli_connect("localhost","root");
mysqli_select_db("mahdb1") or die(mysqli_error($db));
print $unit;
}
else
 include ("../opendb.php");
?>
<style>
td{font-family:verdana;font-size:13px}
a{text-decoration:none;color:black}
a:hover{text-decoration:underline}
</style>
<body bgcolor=ivory>
<center>
<table>
<tr><td align=center><b><?print $unit.' '.$branch?></td></tr>
<tr><td align=center>Trial Balance from <?print datetohtml($df).' to '.datetohtml($dt)?></td></tr>
<tr><td align=center>[Printed by <?print $user?> on <?print date("d-m-Y  h:i:s a")?>]</td></tr>
</table>
<table border=1>
<th>Ledger <th>Dr <th>Cr
<?
$tbl='tbcls'.$brcode.$user;

mysqli_query($db,"delete from $tbl where ltype='led' and dr=0 and cr=0")or die(mysqli_error($db));
$res=mysqli_query($db,"select * from $tbl");

while($row=mysqli_fetch_array($res))
{
 if($row[ltype]=='grp')
  print "<tr><td colspan=4><b>$row[0]</td></tr>";
 else
  print "<tr><td>$row[0]</td><td align=right>$row[1]</td><td align=right>$row[2]</td></tr>";
 $t1+=$row[1];
  $t2+=$row[2];
}
$diff=$t1-$t2;

if($diff!=0)
{
 if($t1>$t2)
 print "<tr><td><b>Opening Contra</td><td align=right></td><td align=right>".abs($diff)."</td></tr>";
else
 print "<tr><td><b>Opening Contra</td><td align=right>".abs($diff)."</td><td align=right></td></tr>";
}
if($t1>$t2)
 print "<tr><td><b>total</td><td align=right>$t1</td><td align=right>$t1</td></tr>";
else
 print "<tr><td><b>total</td><td align=right>$t2</td><td align=right>$t2</td></tr>";

print "</table>";
?>
