<?
 include("test.php");
/*
$link=mysqli_connect("localhost.localdomain","root");
mysqli_select_db("alpdb") or die ("<h3> Error:Database could not be connected-".mysqli_error());
*/
 include("opendb.php");
?>
<style>
td{font-family:verdana;font-size:14}
body{background-color:ivory}
</style>
<center>
<table width=100% border=1>
<tr><td align=right>
<input type=button value="Print" onClick=window.open('prntb.php'); style={font-family:'verdana';font-weight:bold}> </td></tr>
</table>

<font face='arial black'>
Opening Trial Balance
<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")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 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")
	{
       print "<tr onMouseOver=bgColor='alice-blue'; onMouseOut=bgColor='ivory'><td> <blockquote> $row2[led]</td><td align=right>$row2[op]</td></tr>";
        $t1+=$row2[op];
	}
	else 
	{
//	$tp+=$row2[op];
       print "<tr onMouseOver=bgColor='alice-blue'; onMouseOut=bgColor='ivory'><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>";
*/
?>
</table>
********************************************************************************************
<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-->
<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")or die(mysqli_error());
while($row=mysqli_fetch_row($result))
  { 
$tr=0.0;$tp=0.0;$bal=0.0;
        print "\n<tr><td colspan=3><b><font color='brown'>$row[0]";
   $sqq="select * from ledger where upper(grp)='".strtoupper($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")
	{
	$tr+=$row2[op]; 
	}
	else 
	{
	$tp+=$row2[op];
	}
       print "<tr onMouseOver=bgColor='alice-blue'; onMouseOut=bgColor='ivory'><td> <blockquote> $row2[led]</td>";

//     $sq="select * from actrans where ledger='$row2[led]' or dr='$row2[led]' or cr='$row2[led]' or mode='$row2[led]'";
     $sq="select * from actrans where  dr='$row2[led]' or cr='$row2[led]'";
//print "<br>$sq";
//break;
         $ree=mysqli_query($db,$sq)or die("ERROR ".mysqli_error());
          while($r1=mysqli_fetch_array($ree))
          {
            if($r1[cr]==$row2[led])
		{
		$tp+=$r1[amt];
		}
	   if($r1[dr]==$row2[led])
		{
		$tr+=$r1[amt];
		}

     	}

//******************************************************
       $bal=($tr-$tp); $bal=number_format($bal,2,'','');
//******************************************************

if($bal>0)
{
 print "<td align=right>".putComa($bal)."</td><td>&nbsp;</td>";
 $totl+=$bal;
}
else 
{
 print "<td>&nbsp;</td><td align=right>".putComa($bal*-1)."</td>";
 $totr+=$bal;
}
  $tr=0;$tp=0; 
 }

}
$rs=mysqli_query($db,"select opstock from plopstock");
$vv=mysqli_fetch_array($rs);
$totl+=$vv[0];
print "<tr><td><font color=brown><b>Opening Stock</td><td align=right>".putComa($vv[0])."</td></tr>";
print "<tr bgcolor='#5b5858'><td><font color=white><b><center>Total</td>";
print "<td align=right> <font color=white>".putComa($totl)."</td>";
print "<td align=right> <font color=white>".putComa(abs($totr))."</td></tr>";
$differ=abs($totl)-abs($totr);
$differ=number_format($differ,2,'','');
print "<tr><td>".putcoma(abs($differ));

?>
</table>
<br>

<?
 $ops=mysqli_query($db,"select closestock from plopstock");
 $r=mysqli_fetch_row($ops);
 print "<b>Closing Stock : $r[0]</b>";
?>
<?
//include("tb2.php");
?>

