<?php


error_reporting(E_ALL ^ E_NOTICE);

require "classes/DB.class.php";
require "classes/SevenBase.class.php";
require "classes/Seven.class.php";
require "classes/SevenComprobante.class.php";
require "classes/SevenRegistrar.class.php";

if(get_magic_quotes_gpc()){
	
	// If magic quotes is enabled, strip the extra slashes
	array_walk_recursive($_GET,create_function('&$v,$k','$v = stripslashes($v);'));
	array_walk_recursive($_POST,create_function('&$v,$k','$v = stripslashes($v);'));
}

/* Database Configuration. Add your details below */

$dbOptions = array(
	'db_host' => 'localhost',
	'db_name' => 'appsiete_consultacpe',
	'db_user' => 'appsiete_seven',
	'db_pass' => '3owTCLTvNLw'
);

/* Database Config End */

try{
	
	$res = array();
	DB::init($dbOptions);
	$res = Seven::getEmpresa($_POST['ruc_empresa']);

	if ($res['msg']) {
		DB::selectDataBase($res['msg'][0]->nombre_bd);
		$response = array();
		switch($_GET['action']){
	        case 'getComprobantes':
				$response = Seven::getComprobantes($_POST['numero_documento']);
	        	break;    
	        case 'getComprobante':
				$response = Seven::getComprobante($_POST['numero_documento'], $_POST['nombre_comprobante']);
				$response['dominio'] = $res['msg'][0]->subdominio;
				$response['servidor'] = $res['msg'][0]->servidor;
	        	break;    
			default:
				throw new Exception('Wrong action');
		}
		echo json_encode($response);
	}
	else{
		echo json_encode(array('msg'  => "error"));
	}
}
catch(Exception $e){
	die(json_encode(array('error' => $e->getMessage())));
}

?>