<?

session_start();
include_once("../opendb.php");
include_once("../calstock.php");
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$jvno=$_REQUEST['jvno'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='../ind.php' </script>";
 return;
}

if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

$qry=mysqli_query($db,"select * from journal2 where jvno='$jvno'  and brcode='$brcode'");
if(mysqli_num_rows($qry)<=0)
{
 print"<script>alert('invalid payment number');document.location='excel_cshrec1.php';</script>";
} 

$qry=mysqli_query($db,"select * from journal2 where jvno='$jvno'  and brcode='$brcode'");
$row=mysqli_fetch_array($qry);       
$date = $row[1];
$newDate = date("d-m-Y", strtotime($date));


$filename ="excelreport.xls";



 


$res2=mysqli_query($db,"select * from journal2 where jvno='$jvno' and  type='Dr'  and brcode='$brcode' ");
if(mysqli_num_rows($res2)>0)
{
$contents .="  Dr \t Amt\t Narr\t Against  \t Chq no \t \n";

while($res3=mysqli_fetch_array($res2))
  {
   //$totl=$res3[8]+$res3[9];
$contents .=$res3[partic]."\t";

$contents .=$res3[dramt]."\t";
$contents .=$res3[narr]."\t";
$contents .=$res3[against]."\t";
$contents .=$res3[no]."\t \n";


   }
}



$res2=mysqli_query($db,"select * from journal2 where jvno='$jvno' and  type='Cr'  and brcode='$brcode' ");
if(mysqli_num_rows($res2)>0)
{
$contents .="  Cr \t \n";

$contents .="  Cr \t Amt\t Narr\t Against  \t Chq no \t \n";

while($res3=mysqli_fetch_array($res2))
  {
   //$totl=$res3[8]+$res3[9];
$contents .=$res3[partic]."\t";

$contents .=$res3[cramt]."\t";
$contents .=$res3[narr]."\t";
$contents .=$res3[against]."\t";
$contents .=$res3[no]."\t \n";


   }
}




$contents = strip_tags($contents); 

header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);

echo $contents;

?>