<?php 
include "../config.php";
$customer = $_POST['customer'];
//echo $customer;
if ($customer != '')
{
$sql = "select * from customerdetails where code = '$customer' && status !='deleted'";
//echo $sql;
$conn=mysqli_query($connect,$sql);
while($row=mysqli_fetch_array($conn))
{
    $creval = $row['creditlimit'];
    $open = $row['openingbalance'];
    $val = "select ifnull((sum(totalamount)),0)as price from second_transaction where customer = '$customer' && status !='deleted'";
    $con = mysqli_query($connect,$val);
    while($chk = mysqli_fetch_array($con))
        {
              $priceval = $chk['price'];
              $final = $creval - $priceval-$open;
        }
   
}
echo $final;
}
else
{
 echo "";
}

?>
