<?php
require_once "config.php";
$id=$_POST['id'];
$con->autocommit(FALSE);

$sql="select * from invoice_details_history where id='".$id."'";
$query=mysqli_query($con,$sql);
if($query==false){
    die(mysqli_error($con));
}
if($result=mysqli_fetch_array($query)){
    $d=$result['balance'];
    $sql1="update invoice_details set balance=balance+$d where id='".$result['customer_id']."'";
    $query1=mysqli_query($con,$sql1);
    if($query1==false){
    die(mysqli_error($con));
}
}



$sql="delete from invoice_details_history where id='".$id."'";
$query=mysqli_query($con,$sql);
if($query==false){
    die(mysqli_error($con));
}
echo mysqli_affected_rows($con);
$con->commit();


$con->close();
?>