<?
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");
$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
$kar=mysqli_fetch_array($ker);
?>
<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" />
<script type="text/javascript">
$(function() {
$( "#ref_date" ).datepicker("destroy");
     var fyr=document.getElementById('f_yr').value;
     var splv=fyr.explode("-");
     var syr=splv[0];
     var eyr='20'.concat(splv[1]);
     var syr1='01-04-';
     var eyr1='31-03-';
     var stfnyr=syr1.concat(syr);
     var efnyr=eyr1.concat(eyr);
     $("#ref_date").datepicker({ dateFormat: 'dd-mm-yy', minDate: stfnyr, maxDate: efnyr});

$( "#ref_date1" ).datepicker("destroy");
     var fyr=document.getElementById('f_yr').value;
     var splv=fyr.explode("-");
     var syr=splv[0];
     var eyr='20'.concat(splv[1]);
     var syr1='01-04-';
     var eyr1='31-03-';
     var stfnyr=syr1.concat(syr);
     var efnyr=eyr1.concat(eyr);
     $("#ref_date1").datepicker({ dateFormat: 'dd-mm-yy', minDate: stfnyr, maxDate: efnyr});
        });
</script>
<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 grp from  ledger order by grp ASC");
?>
<tr>
<td>Ledger Group</td>
<td><select name='jtype'>
<option value='select'>-Select-</option>
<?
while($row=mysqli_fetch_array($qry))
{
?>
       <option value='<? echo $row['grp'] ?>'><? echo $row['grp'] ?></option>
<?
}
?>
</select>
</td></tr>
<tr><td>Date from </td>
      <td>dd<input type=text name='d' size=2 value='1'>
	  mm<input type=text name='m' size=2 value='04'>
          yy<input type=text name='y' size=4 value='<?Print (date('Y',time()))?>'>
      </td></tr>
   <tr>
     <td> To </td>
      <td>dd<input type=text name='d1' size=2 value='<?Print date('d',time())?>'>
	  mm<input type=text name='m1' size=2 value='<?Print date('m',time())?>'>
          yy<input type=text name='y1' size=4 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($_REQUEST['sprint'])


{
   $jtype = $_REQUEST['jtype'];
   //$cd=$_REQUEST['cd'];
$y=$_REQUEST['y'];
$m=$_REQUEST['m'];
$d=$_REQUEST['d'];
$y1=$_REQUEST['y1'];
$m1=$_REQUEST['m1'];
$d1=$_REQUEST['d1'];
//$cd=str_replace('~','&',$cd);
$df=$y.'-'.$m.'-'.$d;
$dt=$y1.'-'.$m1.'-'.$d1;
print " <center>Transactions from ".implode('-', array_reverse(explode('-', $df))).' to '.implode('-', array_reverse(explode('-', $dt)))."</center>";

  print" <table border=0 cellspacing=1 cellpadding=1 bgcolor=black align=center >";
print"<th width=80>Branch<th width=80>Date <th>Ledger<th>Vouch/Rec. No. <th>Debit <th>Credit <th>Ref. ";
$resultl=mysqli_query($db,"select distinct led,grp,drcr from ledger where  grp='$jtype' order by led")or die(mysqli_error($db));
$i=1;
while($row=mysqli_fetch_array($resultl))
{
print "\n<tr bgcolor='#fffcd6' onMouseOver=bgColor='#f7dbd4'; onMouseOut=bgColor='#fffcd6'>";

$tr=0;$tp=0;


$sql="select * from journal2 where  partic='$row[0]' and date>='$df' and date<='$dt' and brcode in(select brcode from  branch where brstate = '$kar[0]' ) order by date,brcode ";

$result=mysqli_query($db,$sql) or die (mysqli_error($db));

while($row1=mysqli_fetch_array($result))
{
    $brname1=getbrname($row1['brcode'],$db);
   if($row1['type']=='Cr') //$row[cr]==$cd)
    {
        
 print "\n<tr bgcolor='#fffcd6' onMouseOver=bgColor='#f7dbd4'; onMouseOut=bgColor='#fffcd6'><td>$brname1</td><td>".implode('-', array_reverse(explode('-', $row1['date'])))."</td><td>$row[0]</td><td> &nbsp;&nbsp; <a href='viewtransnew.php?code=$row1[jvno]&&df=$df&&dt=$dt&&cd=$cd&&sea=$sea' title='Ref:$row[no]'> To $row1[narr]-($row1[j_type])</a></td><td align=right></td><td align=right>".putComa($row1['cramt'])."</td> <td>$row1[against]:$row1[no]</td>";
//<td align=center><input type=button value='Del' onClick=document.location='deldat.php?code=$row[0]'></td>
print "</tr>";
$totcramt+=$row['cramt'];
  }
 else //if($row[dr]==$cd)
  {
 print "\n<tr bgcolor='#fffcd6' onMouseOver=bgColor='#f7dbd4'; onMouseOut=bgColor='#fffcd6'><td>$brname1</td><td>".implode('-', array_reverse(explode('-', $row1['date'])))."</td><td>$row[0]</td><td> <a href='viewtransnew.php?code=$row1[jvno]&&df=$df&&dt=$dt&&cd=$cd&&sea=$sea' title='Ref:$row1[against] $row1[no]'>By $row1[narr]-($row1[j_type])</a></td><td align=right>".putComa($row1['dramt'])."</td><td align=right></td> <td>$row1[against]:$row1[no]</td>";
//<td align=center><input type=button value='Del' onClick=document.location='deldat.php?code=$row[0]'></td>
print "</tr>";

$totdramt+=$row['dramt'];
 }

}
}
}
?>


