<?php  
	include "conexion.php";
	include "insertar_log.php";
	$id_aplicacion = "0";

	$datos = " Ingresa a obtener_uso_cfdi ";	
	insertarLog($datos,$id_aplicacion);
	
	$sentencia = $conexion->prepare("SELECT valor FROM parametros where id_parametro='app_usos_cfdi' ");
	$sentencia->execute();

	$resultado = $sentencia->get_result();
	$app_usos_cfdi="";

	while($fila = $resultado->fetch_assoc())
	{
		$app_usos_cfdi=$fila['valor'];
	}

	$sentencia->close();

	$datos = " Obtuvo valor app_usos_cfdi=".$app_usos_cfdi;	
	insertarLog($datos,$id_aplicacion);

	if($app_usos_cfdi!="")
	{

		$array = explode(',', $app_usos_cfdi);
		$app_usos_cfdi="";

		for($i=0;$i<sizeof($array);$i++)
		{
			$app_usos_cfdi.= "'".$array[$i]."',";
		}
		$app_usos_cfdi = substr($app_usos_cfdi, 0,-1);
		$sentencia = $conexion->prepare("SELECT id,descripcion FROM cat_usocfdi where id in (".$app_usos_cfdi.")");
	}
	else
	{
		$sentencia = $conexion->prepare("SELECT id,descripcion FROM cat_formapago ");
	}

	
	
	$sentencia->execute();

	$resultado = $sentencia->get_result();
	$cont=0;

	while($fila = $resultado->fetch_assoc())
	{
		$uso_cfdi['id']=$fila['id'];
		$uso_cfdi['descripcion']=$fila['descripcion'];
		$array[$cont] = $uso_cfdi;
		$cont++;
	}

	$datos = " Termina proceso obtener_uso_cfdi";	
	insertarLog($datos,$id_aplicacion);

	echo response(0,"OK",$array);
	$sentencia->close();
	$conexion->close();


	function response($estatus,$estatus_mensaje,$respuesta){
		header("HTTP/1.1".$estatus);

		$response["estatus"]=$estatus;
		$response["estatus_mensaje"]=$estatus_mensaje;
		$response["respuesta"]=$respuesta;
		
		$json_response = json_encode($response, JSON_UNESCAPED_UNICODE);

		echo $json_response;

	}

?>