<?php
require_once __DIR__ . '/../inc/header.php';
require_once __DIR__ . '/../inc/docs.php';
ensure_part2_tables();

$pdo=db();
$id = (int)($_GET['id'] ?? 0);
$invoice_id = (int)($_GET['invoice_id'] ?? 0);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  csrf_check();
  // borrar pago
  $st = $pdo->prepare("DELETE FROM invoice_payments WHERE id=?");
  $st->execute([$id]);
  flash_set('success','Pago eliminado.');
  redirect('facturas/edit.php?id='.$invoice_id);
}

http_response_code(405);
exit('Método no permitido');
