<?

session_start();
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];

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


$sql="select led,op,grp,drcr from ledger where brcode='$brcode' and op!=0 order by grp,led";
$re=mysqli_query($db,$sql)or die(mysqli_error($db));
print"Ledger List";
print "<table border=1>";
print"<th>Ledger<th>Group<th>Debit<th>Credit";
while($row=mysqli_fetch_array($re))
{
$sql1="select * from journal2 where brcode='$brcode'  and partic='$row[0]'";
$re1=mysqli_query($db,$sql1)or die(mysqli_error($db));
//$row11=mysqli_num_rows($re1);
$mopdr =0;
$mopcr =0;
 if(mysqli_num_rows($re1)<=0)
 {
    print "<tr><td>$row[0]</td><td>$row[2]</td>";
	//if ($row[3]=='Dr' && $row[1]<0)
		//print"<td></td><td>$row[1]</td>";

  if($row[3]=='Dr')
    {
         if ($row[1]>=0)
	      $mopdr = $row[1];
         else
             $mopcr = $row[1] * -1;
    }
    if($row[3]=='Cr')
    {
         if ($row[1]>=0)
	      $mopcr = $row[1];
         else
             $mopdr = $row[1] * -1;
    }
print"<td>$mopdr </td><td>$mopcr </td>";
 }
}
print "</table>";
?>
