<?
session_start();
include_once('../opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='index.php'; </script>";
 return;
}
$inno=$_GET['key'];
$re=mysqli_query($db,"select * from ledger where led like '%$inno%' and brcode='$brcode' and grp!='Cash in hand' and grp!='Bank Accounts' order by led asc limit 10") or die("ERR6:".mysqli_error());
$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];

 }
    
$json.= '{"cr":"'.$row[0].'","stock":"'.$test.'","crcbal":"'.$bal.'","rate":"'.addslashes($row[18]).'","reduct":"'.addslashes($row[8]).'","tax":"'.addslashes($row[5]).'"},';

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