<?php
include_once('../../../php/sessionStart.php');
include_once('../../../php/db/dbExec.php');
include_once('../../../php/functions.php');
include_once('../../../php/timezone.php');
include_once('../../../php/privileges.php');

$bitForm = "cnt4060";
$bitMod = "cnt";
$empCod = $_SESSION['empCod'];
$usuCod = utf8_decode($_SESSION['usuCod']);
$usuNom = utf8_decode($_SESSION['usuNom']);

switch ($_POST['action']) {
	case 'consultarCta':
		echo consultarCta();
		break;

	case 'borrar':
		echo borrar();
		break;
}

function consultarCta() {
	global $empCod;

	$priv = new privileges();
	if (!$priv->consult($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorConsult());
	}

	$func = new functions();

	$txtCta=$_POST['txtCta'];

	# QUERYS
	$sCuentas = "SELECT cta.*, 
				TRIM(cta.cta_nom) AS cta_nom 
				FROM cuentas AS cta 
				WHERE cta.cta_emp='$empCod' AND cta.cta='$txtCta'";
	
	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp = $db->sEx($sCuentas, "cuentas");
	$db->close();

	$func = new functions();
	return $func->jsonEncodeArray($resp, "cuentas");
}


function borrar() {
	global $empCod, $usuNom, $bitMod, $bitForm;

	$func = new functions();

	$txtCod=$_POST['txtCod'];
	$txtACta=$_POST['txtACta'];

	# QUERYS
	$dCuentas = "DELETE FROM cuentas WHERE cta_emp='$empCod' AND cta>='$txtCod' AND cta<='$txtACta'";

	# EJECUCION DE QUERYS 
	$db = new dbExec();
	$resp = $db->dEx($dCuentas);
	$db->iEx($func->iBitacora(utf8_decode("Se borraron Cuentas de la: $txtCod  a la:  $txtACta Usuario: ").$usuNom, $bitMod, $bitForm));
	$db->close();

	return json_encode($resp);
}
?>