<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
include_once("utiles.php");

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

$_SESSION['dbname'] = $_POST['database'];
$_SESSION['op__id'] = $_POST['op__id'];
$_SESSION['swsavelog'] = $_POST['swsavelog'];

$cDb_Nam = $_SESSION['dbname'];
$cOp__id = $_SESSION['op__id'];
$SaveLog = $_SESSION['swsavelog'];

$hoynow = getdate();
$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"];
$timeStamp = date("Y-m-d H:i:s");

if ($SaveLog == '1') {
    logs2('++++++++++++++++++++++++++++++++++++apt_actualiza_estatus.php+++++++++++++++++++++++++++++++++++++++++++++++++');
    logs2('database : ' . $cDb_Nam);
    logs2('Op__id   : ' . $cOp__id);
    logs2('swsavelog: ' . $SaveLog);
    logs2('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
}

$connection->query('START TRANSACTION');

$SQL_Update = 'UPDATE ' . $cDb_Nam . '.producto_op SET po_cant_pend=0.00 WHERE (po_op_id="' . $cOp__id . '");';
$result1 = update_Sql($connection, $SQL_Update);

$SQL_Update = 'UPDATE ' . $cDb_Nam . '.operacion SET id_status=1 WHERE (op_id="' . $cOp__id . '");';
$result2 = update_Sql($connection, $SQL_Update);

if (($result1 == true) and ($result2 == true)) {
    $connection->query('COMMIT');
    $msg = array(
        "success" => 'true',
        "mensaje" => 'Procesado correctamente'
    );
} else {
    $connection->query('ROLLBACK');
    $msg = array(
        "success" => 'false',
        "mensaje" => 'Error de procesamiento, no se ha ejecutado ningun cambio.'
    );
};

$jsonData[] = $msg;

header('content-type: application/json');
echo json_encode($jsonData);
@mysqli_close($connection);
/************************************************************************************************************
* ESTE PROCESO SE ENCARGA DE:
* PONE EN CERO LAS CANTIDADES PENDIENTES
* PONE EL ESTATUS DE LA OPERACION EN PROCESADO (=1)
* JOHNN GUTIERREZ: 2020-08-01 01:38AM
************************************************************************************************************/
