<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
   print "<script> alert('Invalid User'); document.location='inde.php' </script>";
   return;
}
include("opendb.php");
include("test.php");
?>
<link href="css/form.css" type="text/css" rel="stylesheet" media="screen" />
<? include('includes/top.php'); ?>
<link rel="stylesheet" href="cal/jquery-ui.css" />
    <script src="cal/jquery-1.9.1.js"></script>
    <script src="cal/jquery-ui1.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />

<body bgcolor='lavender'>
<form name='f1' id='f1' action='<?print $PHP_SELF?>' method='POST' onSubmit="return valid()">
<br>
<CENTER>
<table border=1 cellspacing=1 cellpadding=1 class=report>
<tr bgColor='c1d7bb'><td colspan=7 align=center bgcolor='8A8D89'>
</TD></TR>
<tr><td bgcolor="8A8D89" align='left'><font color='ivory'><b></b></td><td bgcolor="8A8D89" align='left'><font color='ivory'><b></b></td></tr>
<?
$qry=mysqli_query($db,"select DISTINCT(led) from ledger where grp not in('sundry creditors','sundry debtors','employee advance','sundry creditors others')
");
?>
<tr>
<td>Ledger</td>
<td><select name='jtype'>
<option value='select'>-select-</option>
<?
while($row=mysqli_fetch_array($qry))
{
?>
       <option value='<? echo $row[led] ?>'><? echo $row[led] ?></option>
<?
}
?>
</select>
</td></tr>

<tr><td> From </td>
    <td>dd<input type=text name=d size=1 value='<?print date("d",time())?>'>
  mm<input type=text name=m size=1 value='<?print date("m",time())?>'>
  yyyy<input type=text name=y size=3 value='<?print date("Y",time())?>'>
    </td>
</tr>
<tr><td> To </td>
    <td>dd<input type=text name=d1 size=1 value='<?print date("d",time())?>'>
  mm<input type=text name=m1 size=1 value='<?print date("m",time())?>'>
  yyyy<input type=text name=y1 size=3 value='<?print date("Y",time())?>'>
    </td>
</tr>
<tr><td colspan=6 align=center bgcolor='8A8D89'>
<input type=submit value='SHOW' name='sprint'>
<input type=reset value='CANCEL'></td></tr>
</td></tr>
</table>
</center>
<?
if(isset($_POST[sprint]))

{
    
    $y=$_REQUEST['y'];
$m=$_REQUEST['m'];
$d=$_REQUEST['d'];
$dtfrom=$y."-".$m."-".$d;
 
    $y1=$_REQUEST['y1'];
$m1=$_REQUEST['m1'];
$d1=$_REQUEST['d1'];

 
 $dt=$y1."-".$m1."-".$d1;
 
   $jtype = $_REQUEST['jtype'];
   $tblgrpbal=$user."grpballed".$brcode;
mysqli_query($db,"drop table $tblgrpbal");
   mysqli_query($db,"CREATE TABLE $tblgrpbal select * from ledger where led='$jtype' ");
  // print" <table border=0 cellspacing=1 cellpadding=1 bgcolor=black align=center ><tr bgcolor='silver'><td width=5><b>No.</td><td width=300><b>LEDGER </td><td><b>GROUP</td><td><b>Op Bal</td><td><b>Closing Bal</td><td><b>Type</td><td><b>Branch</td></tr>";
$i=1;
  $brres=mysqli_query($db,"select * from branch   where brcode in(select brcode from journal2 where partic='$jtype'   and date>='$dtfrom' and date<='$dt' ) order by brname");
 while($brrow=mysqli_fetch_array($brres))
 {
    // print "<center>Branch : $brrow[1]";
  
print "<table  border=0 cellspacing=3 cellpadding=1 width=100% class='report'> \n<th>Tr. No <th>Date <th>Particulars <th>Debit <th>Credit <th>Narration <th width=50>Type<th>Ref <th>Branch<th>Entry Date";

$result=mysqli_query($db,"select distinct jvno,date from journal2 where partic='$jtype' and brcode='$brrow[0]'  and date>='$dtfrom' and date<='$dt' order by date,jvno")or die(mysqli_error($db));

while($row=mysqli_fetch_array($result))
{
    
    
    $re2=mysqli_query($db,"select * from journal2 where jvno='$row[jvno]' and brcode='$brrow[0]'") or die(mysqli_error($db));
  print "\n<tr ><td>$row[jvno]</td><td>".datetohtml($row[date])."</td><td></td>";
  print "\n<td></td><td></td><td></td><td></td>";
 //print "<td> <td></td></td><td><input type=button value='Print' onclick=window.open('prnvoucher.php?jvno=".$row[jvno]."')></td>";
    while($jvrow=mysqli_fetch_array($re2))
    {
        print "\n<tr><td>&nbsp;</td><td>&nbsp;</td><td>$jvrow[partic]</td>";
        print "<td align=right>".nozero($jvrow[dramt])."</td>";
        print "<td align=right>".nozero($jvrow[cramt])."</td><td>$jvrow[narr]</td><td>$jvrow[j_type]</td><td>$jvrow[against]</td><td>$brrow[1]</td><td>".datetohtml($jvrow[docdt])."</td></tr>"; 
       
 
 }
 
}

print "</table><br>";
 }
} // end save

?>
