<?php 
include "../config.php";
$customer = $_POST['customer'];
//echo $customer;
if ($customer != '')
{
    $output = [];
$opening_balance = mysqli_query($connect,"select salesopening from customerdetails where code='$customer'&& status!='deleted'");
$dis_opening = mysqli_fetch_assoc($opening_balance);
$opening_value = $dis_opening['salesopening'];
$output[]= (object)['code'=>'opening','value'=>$opening_value];
$sales_balance = mysqli_query($connect,"select salescode,ifnull((totalamount),0)as sales from second_transaction where customer='$customer'&& status!='deleted'
UNION
select salescode,ifnull((totalamount),0)as sales from second_transaction_est where customer='$customer'&& status!='deleted'
");
while($sales_rec = mysqli_fetch_array($sales_balance)) {
$output[]= (object)['code'=>$sales_rec['salescode'],'value'=>$sales_rec['sales']];
}
echo json_encode($output);
}
else
{
 echo "";
}

?>
