<?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['c_id'] = $_POST['c_id'];
$_SESSION['c_descripcion'] = $_POST['c_descripcion'];
$_SESSION['pa_id'] = $_POST['pa_id'];
$_SESSION['ciu_id'] = $_POST['ciu_id'];
$_SESSION['c_idfiscal'] = $_POST['c_idfiscal'];
$_SESSION['c_contacto'] = $_POST['c_contacto'];
$_SESSION['c_telefono'] = $_POST['c_telefono'];
$_SESSION['c_credito'] = $_POST['c_credito'];
$_SESSION['c_dias_credito'] = $_POST['c_dias_credito'];
$_SESSION['c_limite_credito'] = $_POST['c_limite_credito'];
$_SESSION['c_vendedor'] = $_POST['c_vendedor'];
$_SESSION['id_contribuyente'] = $_POST['id_contribuyente'];
$_SESSION['c_correo'] = $_POST['c_correo'];
$_SESSION['c_exclusiv_cont'] = $_POST['c_exclusiv_cont'];
$_SESSION['c_apart'] = $_POST['c_apart'];
$_SESSION['c_activo'] = $_POST['c_activo'];
$_SESSION['suc_id'] = $_POST['suc_id'];
$_SESSION['c_ref2'] = $_POST['c_ref2'];
$_SESSION['c_precio'] = $_POST['c_precio'];
$_SESSION['c_credito'] = $_POST['c_credito'];
$_SESSION['c_desc'] = $_POST['c_desc'];
$_SESSION['usuario_id'] = $_POST['usuario_id'];
$_SESSION["c_direccion"]=$_POST['c_direccion'];
		
$hoynow = getdate();
$timeStamp= $hoynow["year"]."-".$hoynow["mon"]."-".$hoynow["mday"] ;
		
$SQL_Update=
	"UPDATE ".$_SESSION['database'].".clientes SET 
	c_descripcion=".$_SESSION['c_descripcion'].",
	pa_id=".$_SESSION['pa_id'].",
	ciu_id=".$_SESSION['ciu_id'].",
	c_idfiscal=".$_SESSION['c_idfiscal'].",
	c_contacto=".$_SESSION['c_contacto'].",
	c_telefono=".$_SESSION['c_telefono'].",
	c_credito=IFNULL(c_credito,0.00),
	c_dias_credito=IFNULL(c_dias_credito,0.00),
	c_limite_credito=IFNULL(c_limite_credito,0.00),
	c_vendedor=".$_SESSION['c_vendedor'].",
	id_contribuyente=".$_SESSION['id_contribuyente'].",
	c_correo=".$_SESSION['c_correo'].",
	c_exclusiv_cont=IFNULL(c_exclusiv_cont,0.00),
	c_apart=IFNULL(c_apart,0.00),
	c_activo=".$_SESSION['c_activo'].",
	suc_id=".$_SESSION['suc_id'].",
	c_ref2=".$_SESSION['c_ref2'].",
	c_direccion=".$_SESSION['c_direccion'].",
    c_u_id_mod=".$_SESSION['usuario_id'].",
    c_modificacion='".$timeStamp."',
    usermodify      = 1,
    useroption      = 2 
    WHERE c_Id=".$_SESSION['c_id'];

	//echo "sql: ".$SQL_Update;

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);
?>
