1ra Versión
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
ini_set('display_errors', '0');
|
||||
error_reporting(0);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
require_once 'conexion.php';
|
||||
|
||||
$rawInput = file_get_contents('php://input');
|
||||
$id = 0;
|
||||
|
||||
if ($rawInput) {
|
||||
$data = json_decode($rawInput, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && isset($data['id'])) {
|
||||
$id = intval($data['id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$id && isset($_POST['id'])) {
|
||||
$id = intval($_POST['id']);
|
||||
}
|
||||
|
||||
if (!$id && isset($_GET['id'])) {
|
||||
$id = intval($_GET['id']);
|
||||
}
|
||||
|
||||
if ($conexion->connect_error) {
|
||||
echo json_encode(['success' => false, 'error' => 'Error de conexión']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'error' => 'ID no proporcionado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$conexion->begin_transaction();
|
||||
|
||||
try {
|
||||
$stmt = $conexion->prepare("DELETE FROM ordenes_productos WHERE ID_Orden IN (SELECT ID_Orden FROM ordenes_compra WHERE ID_Proveedor = ?)");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
$stmt = $conexion->prepare("DELETE FROM ordenes_compra WHERE ID_Proveedor = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
$stmt = $conexion->prepare("DELETE FROM proveedores_productos WHERE ID_Proveedor = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
$stmt = $conexion->prepare("DELETE FROM proveedores WHERE ID_Proveedor = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->affected_rows === 0) {
|
||||
$stmt->close();
|
||||
$conexion->rollback();
|
||||
echo json_encode(['success' => false, 'error' => 'Proveedor no encontrado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conexion->commit();
|
||||
echo json_encode(['success' => true, 'message' => 'Proveedor eliminado']);
|
||||
} catch (Exception $e) {
|
||||
$conexion->rollback();
|
||||
echo json_encode(['success' => false, 'error' => 'Error al eliminar proveedor: ' . $e->getMessage()]);
|
||||
}
|
||||
|
||||
$conexion->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user