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

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

if (! $connection = connectDb()) { 
	die ("err db");
} else {
	$connection->query("SET NAMES 'utf8';");
}
header ('content-type: application/json');

session_start();
$_SESSION['database'] = $_POST['database'];
$_SESSION['suc_id'] = $_POST['suc_id'];
$_SESSION['e_id'] = $_POST['e_id'];
$_SESSION['u_id'] = $_POST['u_id'];
$_SESSION['fecha'] = $_POST['fecha'];
$_SESSION['monto']=$_POST['monto'];
$_SESSION['op_id'] = $_POST['op_id'];

$cDbBame= $_SESSION['database'];
$Cod_Suc= $_SESSION['database'];
$Cod_Est= $_SESSION['e_id'];
$Cod_Usu= $_SESSION['u_id'];
$Val_Fec= $_SESSION['fecha'];
$Val_Mnt= $_SESSION['monto'];
$cCod_Op= $_SESSION['op_id'];
$hoynow = getdate();
$timeStamp= $hoynow["year"]."-".$hoynow["mon"]."-".$hoynow["mday"] ;
		
$SQL_Update= "UPDATE $cDbBame.operacion SET saldo_act = -1*( ABS(saldo_act) - ABS($Val_Mnt) ) WHERE (op_id='$cCod_Op');";

if ($connection->query($SQL_Update)==true)  
{
    $msg = array("success" => "true", "detalle" => "OK");
} 
else 
{
	$msg = array("success" => "false", "detalle" => $conn);
	echo "Error: " . $SQL_Update . "<br>" . $conn->error;
}

print_r(json_encode($msg));

@mysqli_close($connection);
?>
