<?php
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;
}
$cname=$_REQUEST['cname'];

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

$sql="SELECT code,cramt,crdays FROM customer where brcode='$brcode' and cname='$cname'";
$result = mysqli_query($db,$sql);
$row=mysqli_fetch_row($result);
$led=mysqli_query($db,"select op,drcr from ledger where led ='$cname'")or die(mysqli_error($db));
$r=mysqli_fetch_row($led);
if($r[1]=='Cr')
    {
        $mop_bal=$r[0]*-1;
    }
else
    {
        $mop_bal=$r[0];
    }
$jour=mysqli_query($db,"select sum(dramt),sum(cramt) from journal2 where partic ='$cname'")or die(mysqli_error($db));
$s=mysqli_fetch_row($jour);
$mcl_bal=$mop_bal + $s[0] - $s[1];
$inv=mysqli_query($db,"select sum(total) from prod_invoice where customer ='$cname'")or die(mysqli_error($db));
$s=mysqli_fetch_row($inv);
$mbill_amt=$s[0];
$discbl=$row['1']-$mcl_bal;
?>
<input name='reg' id='reg' type='text' style='width:160px;border:1px solid grey; border-style:dotted;' value='<? echo $row['0']; ?>' readonly onchange='showinfo(this.value)' onfocus='sel(this.id)' onKeydown='return handleEnter(this, event)'>
<input type='text' name="mclbl" id="mclbl" value="Balance:&nbsp;<? echo round($mcl_bal,2) ?>">
<input type='text' name="mblamt" id="mblamt" value="Bill Amount:&nbsp;<? echo $mbill_amt ?>">
<input type='text' name="mcrlmt" id="mcrlmt" value="<? echo $row['1']; ?>">
<input type='text' name="mdsbl" id="mdsbl" value="<? echo $discbl ?>">




