<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include_once('opendb.php');
$tbl2="ledger";
$inno=$_GET['key'];
//$re=mysqli_query($db,"select distinct(invno),item,item_code,unitprice,gname,pmode from $tbl2 where invno like '%$inno%' and brcode='$brcode' limit 10 ") or die("ERR6:".mysqli_error($db));
$re=mysqli_query($db,"select * from $tbl2 where led like '%$inno%'  and brcode='$brcode' ORDER BY led asc limit 10") or die("ERR6:".mysqli_error($db));
$json="";
while($row=mysqli_fetch_array($re))
{
$balres=mysqli_query($db,"select sum(dramt),sum(cramt) from journal2 where brcode='$brcode' and partic='$row[0]'");
 $balrow=mysqli_fetch_row($balres);
 if($row['drcr']=='Dr')
 {
 $bal=($balrow[0]+$row[2])-$balrow[1]; 
 }
 else
 {
 $bal=$balrow[1]+$row[2]-$balrow[0];
 }
$test="";
$json.= '{"cr":"'.$row[0].'","stock":"'.$test.'","cbal":"'.$bal.'","rate":"","reduct":"","tax":"'.addslashes($row[5]).'"},';

}
echo '['.trim($json,',').']';
?>
