<?php
/*****************************************************************************************************************************************
 * DEV: CONTRALORIA DE ESTADOS
 * PROYECTO: SISTEMA INTEGRAL ADMINISTRATIVO DE CONTRALORIAS DE ESTADOS
 * MODULO: index
 * PROCESO: index del sistema
 * PROGRAMADORES:
 * | # |          NOMBRES Y APELLIDOS              |               CORREO               |          TELEFONO              |
 * | 1 |          Pablo Rodríguez                  |prodriguez@contradeltamacuro.gob.ve |         0426-7992529           |
 * |___|___________________________________________|____________________________________|________________________________|
 *
 * VERSION
 *
 * |          PROGRAMADOR                  |          FECHA          |       VERSION      |
 * |               #1                      |        21-07-2015       |         1.0        |
 * |_______________________________________|_________________________|____________________|
 *
 *****************************************************************************************************************************************/
require_once ROOT.'librerias'.DS.'gump.class.php';
require_once ROOT.'librerias'.DS.'Select.php';
require_once ROOT.'librerias'.DS.'ConsultarDescripcion.php';

class DesmayorizarVoucherControlador extends Controlador
{

    public function __construct()
    {
        parent::__construct();
        Session::metAcceso();
        $this->DesmayorizarVoucher = $this->metCargarModelo('DesmayorizarVoucher');
    }

    public function metIndex()
    {
        $complementosCss = array(
            'DataTables/jquery.dataTables',
            'DataTables/extensions/dataTables.colVis941e',
            'DataTables/extensions/dataTables.tableTools4029',
        );

        $js= array(
            'materialSiace/core/demo/DemoTableDynamic',
            'Aplicacion/appFunciones',
            'Scripts/Form',
            'materialSiace/core/demo/PipeLine'
        );

        $this->atVista->metCargarCssComplemento($complementosCss);
        $this->atVista->metCargarJs($js);
        $this->atVista->assign('listado',$this->DesmayorizarVoucher->metListar());
        $this->atVista->metRenderizar('DesmayorizarVoucher');
    }

    /**
    * Activa el proceso para desmayorizar el voucher
    */
    public function metDesmayorizarVoucher()
    {
        $this->DesmayorizarVoucher->metDesmayorizarVoucher(['pk_num_voucher_mast'=>$_POST['id']]);
        $jsondata = [
           'status' => 'OK',
           'mensaje' => 'Registro Desmayorizado Exitosamente',
           'id' => $_POST['id'],
        ];
        echo json_encode($jsondata);
        exit();
    }

    public function metJsonDataTabla()
    {

        ##Obtengo los roles del usuario
        $rol = Session::metObtener('perfil');

        ##Capturo la busqueda enviada por la datatabla, Nota: esto es obligatorio
        $busqueda = $this->metObtenerFormulas('search');

        ##  filtro adicional
        $filtrar = "";
        if ($_GET)
        {
            //Si selecionamos el tipo de contabilidad
            if (!empty($_GET['fnum_contabilidades']))
            {
                $filtrar.= " AND vm.fk_cbb005_num_contabilidades = '$_GET[fnum_contabilidades]'";
            }
            //Si selecionamos algún tipo de voucher
            if (!empty($_GET['fnum_voucher']))
            {
                $filtrar.= " AND  vm.fk_cbc003_num_voucher = '$_GET[fnum_voucher]'";
            }
            //Si seleccionamos el estado del voucher
            if (!empty($_GET['festado_voucher']))
            {
                $filtrar.= " AND  vm.ind_estatus = '$_GET[festado_voucher]'";
            }
            //Si seleccionamos el periodo del voucher
            if (!empty($_GET['fperiodo']))
            {
                $valor_f  = explode("-", $_GET['fperiodo']);
                $ind_anio = $valor_f[0];
                $ind_mes  = $valor_f[1];

                $filtrar.= " AND  vm.ind_mes = '$ind_mes' AND vm.ind_anio='$ind_anio' ";
            }

        }

        ##construyo el sql, Nota: esto es obligatorio
        $sql = "SELECT
                                        vm.*,
                                        o.pk_num_organismo,
                                        d.pk_num_dependencia,
                                        acv.ind_descripcion
                                  FROM
                                        cb_b001_voucher vm
                                        INNER JOIN a001_organismo o ON (vm.fk_a001_num_organismo = o.pk_num_organismo)
                                        LEFT JOIN a004_dependencia d ON (vm.fk_a004_num_dependencia = d.pk_num_dependencia)
                                        INNER JOIN cb_c003_tipo_voucher acv ON (vm.fk_cbc003_num_voucher = acv.pk_num_voucher)
                                  WHERE
                                        vm.ind_estatus= 'MA' $filtrar
                               
        ";
//var_dump($sql);exit();
        if ($busqueda['value']) {
            #concateno la busqueda si existe, Nota: esto es obligatorio
            $sql .="
                AND ( 
                    vm.pk_num_voucher_mast LIKE '%$busqueda[value]%' OR 
                    vm.ind_voucher LIKE '%$busqueda[value]%' OR
                    acv.ind_descripcion LIKE '%$busqueda[value]%' OR
                    vm.txt_titulo_voucher LIKE '%$busqueda[value]%' 
                ) 
            ";
        }

        #creo un arreglo de los campos a mostrar, Nota: esto es obligatorio appFunciones
        $campos = [
            'pk_num_voucher_mast',
            'ind_periodo',
            'ind_voucher',
            'ind_descripcion',
            'txt_titulo_voucher',
            'ind_estatus'
        ];

        #creo un arreglo de los campos a mostrar, Nota: esto es obligatorio pipeline
        /*$campos = array('pk_num_voucher_mast','ind_periodo','ind_voucher','ind_descripcion','txt_titulo_voucher','ind_estatus');*/

        #campo primario de la tabla, Nota: esto es obligatorio
        $clavePrimaria = 'pk_num_voucher_mast';

        $campos['boton']['ver'] = '<button class="logsUsuario btn ink-reaction btn-raised btn-xs btn-primary Desmayorizar" idRegistro="'.$clavePrimaria.'"  boton="Desmayorizar" title="Desmayorizar"
                                                    descipcion="El usuario mayorizó un post" titulo="Estas Seguro?" mensaje="Esta seguro que desea desmayorizar el Voucher!!" id="desmayorizar_voucher" title="Desmayorizar">
                                                <i class="md md-swap-horiz" style="color: #ffffff;"></i>
                                        </button>
        ';



        #hago el llamado de la datatabla del controlador principal.
        $this->metDataTabla($sql,$campos,$clavePrimaria);

    }

}
