/*
Theme Name:         Bakan
Theme URI:          http://demo.wpthemego.com/themes/sw_bakan/
Description:        Bakan - Elementor WooCommerce WordPress Theme
Author:             magentech
Author URI:        	https://themeforest.net/user/magentech/
Version:            1.4.15
License:            GNU General Public License v2 or later
Tested up to:       6.8
Requires PHP:       7.4

License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: rtl-language-support, sticky-post, two-columns
Text Domain: bakan

This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/

.wp-caption {
	margin-bottom: 1.75em;
	max-width: 100%;
}

.wp-caption img[class*="wp-image-"] {
	display: block;
	margin: 0;
}

.wp-caption .wp-caption-text {
	color: #686868;
	font-size: 13px;
	font-style: italic;
	line-height: 1.6153846154;
	padding-top: 0.5384615385em;
}

.bypostauthor > article .fn:after {
	content: "\f304";
	left: 3px;
	position: relative;
	top: 5px;
}

.gallery-caption {
	color: #686868;
	display: block;
	font-size: 13px;
	font-style: italic;
	line-height: 1.6153846154;
	padding-top: 0.5384615385em;
}
/* Text meant only for screen readers. */
.screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute !important;
	width: 1px;
	word-wrap: normal !important; /* Many screen reader and browser combinations announce broken words as they would appear visually. */
}

.screen-reader-text:focus {
	background-color: #eee;
	clip: auto !important;
	clip-path: none;
	color: #444;
	display: block;
	font-size: 1em;
	height: auto;
	left: 5px;
	line-height: normal;
	padding: 15px 23px 14px;
	text-decoration: none;
	top: 5px;
	width: auto;
	z-index: 100000;
	/* Above WP toolbar. */
}
add_action('rest_api_init', function () {
    register_rest_route('borges/v1', '/buscar-comprobante', array(
        'methods' => 'POST',
        'callback' => 'borges_buscar_comprobante',
        'permission_callback' => '__return_true'
    ));
});

function borges_buscar_comprobante($request) {

    $serie  = sanitize_text_field($request['serie']);
    $numero = sanitize_text_field($request['numero']);
    $fecha  = sanitize_text_field($request['fecha']);
    $total  = sanitize_text_field($request['total']);

    $mysqli = new mysqli(
        "localhost",
        "joseluis_user_sys_fe",
        "1[%cl2GE6SQ]",
        "joseluis_bd_sys_fe"
    );

    if ($mysqli->connect_errno) {
        return ["status"=>"error","msg"=>"Error conexión BD"];
    }

    $id_empresa = 53;

    $sql = "SELECT serie_comprobante, numero_comprobante, fecha_comprobante, total, ruta_xml, name_xml
            FROM doc_electronico
            WHERE id_contribuyente = ?
            AND serie_comprobante = ?
            AND numero_comprobante = ?
            AND fecha_comprobante = ?
            AND total = ?
            AND estado_documento = 'activo'
            LIMIT 1";

    $stmt = $mysqli->prepare($sql);
    $stmt->bind_param("isiss", $id_empresa, $serie, $numero, $fecha, $total);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        return [
            "status" => "ok",
            "documento" => $result->fetch_assoc()
        ];
    } else {
        return [
            "status" => "fail",
            "msg" => "Documento no encontrado"
        ];
    }
}