<?php 
include '../includes/config.php';
if (isset($_REQUEST['del'])) {
  // Get sale_id
  $id = intval($_GET['del']);
  
  // Delete all records with same invoice
  $sql = "DELETE FROM units WHERE id=:id";
  $query = $conn->prepare($sql);
  $query->bindParam(':id', $id, PDO::PARAM_INT);
  $query->execute();

  // Check if any records were deleted
  $count = $query->rowCount();
  if ($count > 0) {
    echo "<script>alert('Records deleted successfully.');</script>";
  } else {
    echo "<script>alert('No records found to delete.');</script>";
  }

  // Redirect to the list-sale page
  echo "<script>window.location.href='../units.php'</script>";
}

?>

