<?
 session_start();
  $brcode = $_SESSION['brcode'];
   $user= $_SESSION['user'];
 $df= $_REQUEST['df'];   
$dt= $_REQUEST['dt'];   
$cd= $_REQUEST['cd'];   
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());
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>
<?
$br=str_replace(' ','',$branch);
$br=str_replace('(','',$br);
$br=str_replace(')','',$br);

$tbl1='tbclssum'.$brcode.$user;


$cd=str_replace('~','&',$cd);
$res=mysqli_query($db,"select led,opdr,opcr,dr,cr,cldr,clcr from  $tbl1 where grp1='$cd'");
?>
<th>Group <?print $cd?> <th>Opdr<th>OpCr<th>Dr <th>Cr<th>ClDr<th>ClCr
<?
while($row=mysqli_fetch_array($res))
{
 if($row[1]>'0' ||$row[2]>'0' || $row[3]>'0'|| $row[4]>'0')
{
  print "<tr><td><a href='../vmledgerdt.php?cd=$row[0]&df=$df&dt=$dt' title='Click to view ledger' target='m'> $row[0]</td><td align=right>$row[1]</td><td align=right>$row[2]</td><td align=right>$row[3]</td><td align=right>$row[4]</td><td align=right>$row[5]</td><td align=right>$row[6]</td></tr>";
 }
  $t1+=$row[1];
  $t2+=$row[2];
  $t3+=$row[3];
  $t4+=$row[4];
  $t5+=$row[5];
  $t6+=$row[6];





}
$diff=$t3-$t4;

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

print "</table>";
?>


