<?php
include_once ("utiles.php");
include_once ("apt_funciones.php");

if (! $connection = connectDb()) {
    die("err db");
} else {
    $connection->query("SET NAMES 'utf8';");
}

date_default_timezone_set("America/Panama");
error_reporting(E_ALL & ~ E_NOTICE & ~ E_WARNING);

session_start();

$_SESSION['database'] = $_POST['database'];
$_SESSION["suc_id"] = $_POST['suc_id'];
$_SESSION["op__id"] = $_POST['op__id'];
$_SESSION["id_cte"] = $_POST['id_cte'];
$_SESSION["op_tipo"] = $_POST['op_tipo'];
$_SESSION['swsavelog'] = $_POST['swsavelog'];

$cDb_Nam = $_SESSION["database"];
$cSuc_id = $_SESSION["suc_id"];
$cOp__id = $_SESSION["op__id"];
$cCod_Ct = $_SESSION["id_cte"];
$cOp_Tip = $_SESSION["op_tipo"];
$SaveLog = $_SESSION['swsavelog'];

/*
$cDb_Nam = '699_bayshoreaptos';
$cSuc_id = '2';
$cOp__id = '220000002';
$cCod_Ct = '8';
$cOp_Tip = '3';
$SaveLog = '1';
*/

$hoynow = getdate();
$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"];
$timeStamp = date("Y-m-d H:i:s");
try {
    
    if ($SaveLog == '1') {
        logs2('++++++++++++++++++++++++++++++++++++++++++++++apt_anula_op_po.php+++++++++++++++++++++++++++++++++++++++++++++++++');
        logs2('database : ' . $cDb_Nam);
        logs2('Sucursal : ' . $cSuc_id);
        logs2('Op__id   : ' . $cOp__id);
        logs2('Cte_Id   : ' . $cCod_Ct);
        logs2('Detalle  : ' . $cpDetalle);
        logs2('Stat_id  : ' . $cId_Stat);
        logs2('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
    }
    ;
    
    $resp = Anula_OP_AND_PO($connection, $cDb_Nam, $cSuc_id, $cCod_Ct, $cOp_Tip, $cOp__id, $SaveLog);
    
    if ($SaveLog == '1') {
        logs2('RESULT:' . ($resp ? 'true' : 'false'));
        logs2('FIN+++++++++++++++++++++++++++++++++++++++++++apt_anula_op_po.php+++++++++++++++++++++++++++++++++++++++++++++++++');
        logs2('', false);
    }
    ;
    
    if ($resp == true) {
        $resp = 'true';
        $msg = array(
            "success" => "true",
            "detalle" => "OK"
        );
    } else {
        $resp = 'false';
        $msg = array(
            "success" => "false",
            "detalle" => "NO SE ENCONTRARON DATOS DEL APARTADO #[" . $cOp__id . "]"
        );
    }
    ;
} catch (Exception $e) {
    $resp = 'false';
    $msg = array(
        "success" => "false",
        "detalle" => "NO SE ENCONTRARON DATOS DEL APARTADO #[" . $cOp__id . "]"
    );
    //echo "<br>" . $connection->error;
}
;
$jsonData[] = $msg;

header('content-type: application/json');
echo json_encode($jsonData);

@mysqli_close($connection);
?>