<?
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='inde.php'; </script>";
 return;
}
$tbl2="prod_invoice";
$dr=$_GET['key'];
$re=mysqli_query($db,"select * from ledger where grp='Bank accounts' or grp='Bank O/d' and led like '%$dr%' and brcode='$brcode' order by led limit 10") or die(mysqli_error($db));
$json="";
while($row=mysqli_fetch_array($re))
	{
		$bal=0;
		$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.= '{"dr":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($row[2]).'","dbal":"'.addslashes($bal).'","reduct":"'.addslashes($row[10]).'","tax":"'.addslashes($rw[0]).'"},';

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