<?php
include '../comunes_php/cors.php';
    include '../comunes_php/Log.class.php'; 
    $log = new Log("app_trace", "./");

$id = intval($_REQUEST['id']);
	include '../rdb/conn.php';

try {    
mysqli_query( $conn,"SET AUTOCOMMIT=0");
mysqli_query( $conn,"START TRANSACTION");

$sql = "delete from contrato_detalle_adicionales  where contrato_id={$id}";
@mysqli_query( $conn,$sql);
$log->insert($sql, false, false, false);
	
                	    
$sql = "delete from contratos_detalle where contrato_id={$id}";
@mysqli_query( $conn,$sql);
$log->insert($sql, false, false, false);


$sql = "delete from estados_de_contrato where contrato_id={$id}";
@mysqli_query( $conn,$sql);
$log->insert($sql, false, false, false);
                	    


$sql = "delete from reclamos_contrato where contrato_id={$id}";
@mysqli_query( $conn,$sql);
$log->insert($sql, false, false, false);

$sql = "delete from contrato_pagos where contrato_id={$id}";
@mysqli_query( $conn,$sql);
$log->insert($sql, false, false, false);                	    


$sql = "delete from contratos_cabecera where id={$id}";
@mysqli_query( $conn,$sql);
$log->insert($sql, false, false, false);
                	    

            
mysqli_query( $conn,"COMMIT");
echo json_encode(array('success'=>true));

} catch(exception $error) {
    
mysqli_query( $conn,"ROLLBACK");
$log->insert($error->getMessage(), false, false, false);
echo 'Ocurrio el siguiente error'. $error->getMessage();    
}
?>