<?php 
session_start(); 
require_once('../conexion.php');
require_once('../include/sesiones.php');
$coab_id=limpiar($_GET['coab_id']);

$sql=mysqli_query($con, "SELECT * from  compra_abonos where coab_id='$coab_id' ");
$row=mysqli_fetch_array($sql);
 $com_id=$row["compras_com_id"];
   
                       $files = glob("../img/factura-abono/$com_id/$coab_id.jpg");
                        if(count($files) > 0) 
                        { 
                            foreach($files as $file) 
                            { 
                             unlink ("../img/factura-abono/$com_id/$coab_id.jpg");//eliminar marca de la carpeta 
                       
                            } 
                        } else { 
                       
                         } 




$borrar_sql=mysqli_query($con,"DELETE FROM compra_abonos WHERE coab_id=$coab_id") or die(mysqli_error($con));

$sql1=mysqli_query($con, "SELECT count(coab_id) as abonos from  compra_abonos where compras_com_id='$com_id' ");
$row1=mysqli_fetch_array($sql1);
  $abonos=$row1["abonos"]; 

if ($abonos==0) {
   if(file_exists("../img/factura-abono/$com_id"))
   {
    rmdir("../img/factura-abono/$com_id");//eliminar carpeta 
  }
}


echo    '<div class="alert alert-danger alert-dismissable">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            <strong>Abono!</strong> Eliminado correctamente.
        </div>';
  
?>