<? 
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$branch = $_SESSION['branch'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");
include("../test.php"); 
$ad=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($ad);
$brname=explode(',',$branch);
$jvno=$_REQUEST['jvno'];
$re=mysqli_query($db,"select distinct jvno,j_type from journal2 where brcode='$brcode' and jvno='$jvno'");
$row1=mysqli_fetch_row($re);
//print $row1[1];

if($row1[1]=='BR')
    $jtype="Bank Receipt";
else if($row1[1]=='BP')
    $jtype="Bank Payment";
else if($row1[1]=='CR')
    $jtype="Cash Receipt";
else if($row1[1]=='CP')
    $jtype="Cash Payment";
else if($row1[1]=='JV')
    $jtype="Journal Voucher";
else if($row1[1]=='V sale')
    $jtype="Vehicle Sale";
else if($row1[1]=='V pur')
    $jtype="Vehicle Purchase";
else if($row1[1]=='TDSJV')
    $jtype="TDS Journal";
else if($row1[1]=='I pur')
    $jtype="Item Purchase";
else if($row1[1]=='P Ret')
    $jtype="Purchase Return";
else if($row1[1]=='sale ret')
    $jtype="Sales Return";

?>

<center>
<table width=100%>
<tr><td align=center><p style={letter-spacing:9;font-size:15}><b><?print strtoupper($brname[0])?></TD></TR>

<TR><TD ALIGN=CENTER><font size=2><?print strtoupper($brrow['braddr']).', '.strtoupper($brrow['brcity'])?></td></tr>
<tr><td align=center><br><U><font size=2><? print $jtype?> </U></TD></TR>
</center>
<tr><td align=left><br><? print $jtype?> No. :
<?

$re=mysqli_query($db,"select distinct jvno,j_type,tr_no,no from journal2 where brcode='$brcode' and jvno='$jvno'  ");
$row1=mysqli_fetch_array($re);
if ($jtype == "Journal Voucher")
{	

	print $row1[0]."</td></tr></table>";		
}
else
{	
	if($row1[1]=='GST Expense')
	print $row1[3]."</td></tr></table>";
	else
	print $row1[2]."</td></tr></table>";
}
//print $row1[1];
$re=mysqli_query($db,"select distinct jvno,j_type,tr_no from journal2 where brcode='$brcode' and jvno='$jvno'");
print "<table border=0 cellspacing=3 cellpadding=1 width=100%><font size=2><th><font size=2>Date<hr> <th><font size=2>Particulars <hr><th><font size=2>Debit<hr> <th><font size=2>Credit<hr> <th><font size=2>Narration <hr> ";
$mtot_dr=0;
$mtot_cr=0;
while($row=mysqli_fetch_array($re))
{
    $re2=mysqli_query($db,"select * from journal2 where jvno='$row[jvno]' and brcode='$brcode' order by dramt desc") or die(mysqli_error());
    while($jvrow=mysqli_fetch_array($re2))
    {
	 $mdate = implode('-', array_reverse(explode('-', $jvrow['date'])));
        print "\n<tr><td align=center><font size=1>$mdate</td><td>|<font size=1>$jvrow[partic]</td>";
        print "<td align=right><font size=1>".nozero($jvrow['dramt'])."|</td>";
        print "<td align=right><font size=1>".nozero($jvrow['cramt'])."|</td><td><font size=1>$jvrow[narr]</td></tr>";
        $mtot_dr +=$jvrow['dramt'];
	$mtot_cr +=$jvrow['cramt'];
    }
     print "<tr><td colspan=9 ></td></tr>";
}
print "<tr><td colspan=2 align='center'>TOTAL</td><td align='right'>".putComa($mtot_dr)."</td><td align='right'>".putComa($mtot_cr)."</td></tr><tr><th><br><br>Authorised Signatory</tr></table>";
?>