예제 #1
0
    function ObtieneLista($arResult, $lngTotalPag, $lngPag, $strUsuario, $strNumDesde, $strNumHasta, $datFechaAltaDesde, $datFechaAltaHasta, $lngEstado, $Tipificacion)
    {
        require_once '../general/' . $_SESSION['mapeo'];
        require_once '../general/funcionesGenerales.php';
        logger('traza', 'clsCADNCS.php-', 'clsCADNCS->ObtieneLista(' . $strUsuario . ',' . $strNumDesde . ',' . $strNumDesdeAnio . ',' . $strNumHasta . ',' . $strNumHastaAnio . ',' . $datAltaDesde . ',' . $datAltaHasta . ')');
        //PAra llamara a la función hay que pasar 0-> Sí sólo queremos la visbilidad sobre los departamento,  1  si queremos la visibilidad sobre las oficinas
        $visibilidad = DameVisibilidad($strUsuario, 1);
        $strSQL = 'SELECT N.lngId as Numero, N.strNoConfServ, DATE_FORMAT(N.datFechaAlta,"%d/%m/%Y") AS datFechaAlta,, Left(N.strReqIncumplido, 30) as ReqIncumplido,.
		        "(D.strDescripcion) as Departamento, N.lngAccion .
		        "from tbnoconfserv N, tbusuarios U, tbdepartamentos D, tbempleados AS E, tboficinas O  .
		        "Where N.lngIdDepartamento = D.lngId And E.lngIdEmpleado=U.lngIdEmpleado and U.strUsuario=" .strUsuario. "  .
		        "And (N.lngIdEmpleado=U.lngIdEmpleado or N.lngIdResponsableAfect=U.lngIdEmpleado or ".
		        " U.lngPermiso = 2  or U.lngPermiso = 1  or N.strCodigoOficina = O.strCodigo or N.strCodigoOficina in (select lngVisibilidad from tbVisibilidad2 where lngidEmpleado = U.lngIdEmpleado))  and E.lngIdOficina = O.lngId .
		        " U.lngPermiso = 2  or U.lngPermiso = 1  or N.strCodigoOficina = O.strCodigo) and E.lngIdOficina = O.lngId ';
        if ($visibilidad != -1) {
            $strSQL = $strSQL . " (U.lngPermiso = 2 OR U.lngPermiso = 1 OR N.strCodigoOficina = O.strCodigo OR N.strCodigoOficina IN (" . $visibilidad . ")) AND EResp.lngIdOficina = O.lngId ";
        } else {
            $strSQL = $strSQL . " (U.lngPermiso = 2 OR U.lngPermiso = 1 OR N.strCodigoOficina = O.strCodigo OR N.strCodigoOficina IN (SELECT lngVisibilidad FROM tbvisibilidad2 WHERE lngidEmpleado = U.lngIdEmpleado)) AND EResp.lngIdOficina = O.lngId ";
        }
        $strSQL = $strSQL . " AND U.lngIdEmpleado = EResp.lngIdEmpleado AND U.strUsuario = '" . $strUsuario . "'  AND R.lngStatus<>0";
        //condiciones de filtros
        if ($lngEstado != 0) {
            if ($lngEstado == 1) {
                //Pdte. Analisis
                $strSQL = $strSQL . " AND ISNULL(datFechaAceptadoResponsable) ";
            } else {
                if ($lngEstado == 2) {
                    //Pdte. cierre
                    $strSQL = $strSQL . " AND NOT ISNULL(datFechaAceptadoResponsable) AND lngCerrado = 0 ";
                }
            }
        }
        //Busqueda por numero
        if ($strNumDesde != '') {
            $strSQL = $strSQL . " AND N.strNoConfServ >= '" . $strNumDesde . "' ";
        }
        if ($strNumHasta != '') {
            $strSQL = $strSQL . "AND N.strNoConfServ >='" . $strNumHasta . "'";
        }
        //veo si hay datos en las fechas y añado los filtros
        if ($datAltaDesde != '') {
            $strSQL = $strSQL . " AND DATE_FORMAT(N.datFechaAlta,'%d/%m/%Y') >= '" . $datAltaDesde . "'";
        }
        if ($datAltaHasta != '') {
            $strSQL = $strSQL . " AND DATE_FORMAT(N.datFechaAlta,'%d/%m/%Y') <= '" . $datAltaHasta . "'";
        }
        //si no hubiese datos de fechas se filtra por los del año actual
        if ($datAltaDesde == '' && $datAltaHasta == '') {
            date_default_timezone_set('Europe/Madrid');
            $datAltaDesde = '01/01/' . date("Y");
            $strSQL = $strSQL . " AND DATE_FORMAT(N.datFechaAlta,'%d/%m/%Y') >= '" . $datAltaDesde . "'";
        }
        $strSQL = $strSQL . " ORDER BY N.datFechaAlta DESC, N.strNoConfServ DESC";
        $db = new Db();
        //$db->conectar($this->getStrBD());
        $db->conectar($_SESSION['mapeo']);
        $stmt = $db->ejecutar($strSQL);
        $db->desconectar();
        $arcDoc = '';
        if ($stmt) {
            //preparamos los numeros ordenados de 'desde' y 'hasta'
            $desdeOrd = $strNumDesdeAnio . $strNumDesde;
            $hastaOrd = $strNumHastaAnio . $strNumHasta;
            //recoremos la consulta y vamos incluyendo o descartando los resultados segun si cumplen o no el filtro
            while ($row = mysql_fetch_array($stmt, MYSQL_ASSOC)) {
                //extraemos el numero de reclamacion para poder comprobar que cumple los filtros
                $numNoConf = explode('/', $row['strNoConfServ']);
                //preparamos el numero ordenado primero el año y despues el numero
                $numNCOrdenado = $numNoConf[1] . $numNoConf[0];
                //ahora comprobamos si tenemos datos en 'desde', 'hasta' o 'desde' y 'hasta'
                //hay datos de 'desde' y 'hasta'
                if ($strNumDesde != '' && $strNumDesdeAnio != '' && $strNumHasta != '' && $strNumHastaAnio != '') {
                    //comprobamos si el nº reclamacion esta entre estos los numeros
                    if ($desdeOrd <= $numNCOrdenado && $hastaOrd >= $numNCOrdenado) {
                        //si lo cumple lo incluimos en el listado
                        $this->guardarArrayListar($arcDoc, $row);
                    }
                } else {
                    if ($strNumDesde != '' && $strNumDesdeAnio != '' && $strNumHasta == '' && $strNumHastaAnio == '') {
                        //comprobamos si el nº reclamacion es igual o mayor que el 'desde'
                        if ($desdeOrd <= $numNCOrdenado) {
                            //si lo cumple lo incluimos en el listado
                            $this->guardarArrayListar($arcDoc, $row);
                        }
                    } else {
                        if ($strNumDesde == '' && $strNumDesdeAnio == '' && $strNumHasta != '' && $strNumHastaAnio != '') {
                            //comprobamos si el nº reclamacion es igual o menor que el 'hasta'
                            if ($hastaOrd >= $numNCOrdenado) {
                                //si lo cumple lo incluimos en el listado
                                $this->guardarArrayListar($arcDoc, $row);
                            }
                        } else {
                            //se incluye tal cual en el listado
                            $this->filtrarArray($arcDoc, $stmt, $strNumDesde, $strNumDesdeAnio, $strNumHasta, $strNumHastaAnio);
                        }
                    }
                }
            }
            //devuelvo el listado
            logger('traza', 'clsCADNCS.php-', 'clsCADNCS->ObtieneLista(' . $strUsuario . ',' . $strNumDesde . ',' . $strNumDesdeAnio . ',' . $strNumHasta . ',' . $strNumHastaAnio . ',' . $datAltaDesde . ',' . $datAltaHasta . '): Hay listado datos');
            return $arcDoc;
        } else {
            //no hay datos
            logger('traza', 'clsCADNCS.php-', 'clsCADNCS->ObtieneLista(' . $strUsuario . ',' . $strNumDesde . ',' . $strNumDesdeAnio . ',' . $strNumHasta . ',' . $strNumHastaAnio . ',' . $datAltaDesde . ',' . $datAltaHasta . '): Esta vacio, no hay datos');
            return '';
        }
    }
예제 #2
0
 function ObtieneListaRespuestas($strUsuario, $strNumDesde, $strNumDesdeAnio, $strNumHasta, $strNumHastaAnio, $datAltaDesde, $datAltaHasta)
 {
     require_once '../general/' . $_SESSION['mapeo'];
     require_once '../general/funcionesGenerales.php';
     logger('traza', 'clsCADEnc.php-', 'clsCADEnc->ObtieneLista()');
     //PAra llamara a la función hay que pasar 0-> Sí sólo queremos la visbilidad sobre los departamento,  1  si queremos la visibilidad sobre las oficinas
     $visibilidad = DameVisibilidad($strUsuario, 1);
     //PACO 1/7/2015  ??
     //        $strSQL = "
     //                     SELECT DISTINCT E.lngId, R.lngNumResp, E.strNombre, DATE_FORMAT(E.datFecha,'%d/%m/%Y') AS datFecha, concat_ws(' ', E1.strNombre, E1.strApellidos) as responsable, E.numPreguntas, lngEstado
     //                     from cabeceraencuesta E, tbempleados E1, tbresultados_esp R
     //                     where E.lngIdEmpleado = E1.lngIdEmpleado and R.lngIdEncuesta=E.lngId and E.lngEstado <> 9
     //                 ";
     //esta consulta descarta las encuesta de 'encuestasdescartadas'
     //        $strSQL = "
     //                    SELECT DISTINCT E.lngId, R.lngNumResp, E.strNombre, DATE_FORMAT(E.datFecha,'%d/%m/%Y') AS datFecha, concat_ws(' ', E1.strNombre, E1.strApellidos) as responsable, E.numPreguntas, lngEstado
     //                    FROM cabeceraencuesta E, tbempleados E1, tbresultados_esp R
     //                    WHERE E.lngIdEmpleado = E1.lngIdEmpleado
     //                    AND R.lngIdEncuesta=E.lngId
     //                    AND E.lngEstado <> 9
     //                    AND R.lngNumResp NOT IN (SELECT NumResp FROM encuestasdescartadas)
     //                 ";
     $strSQL = "\r\n                    SELECT DISTINCT E.lngId, R.lngNumResp, E.strNombre, DATE_FORMAT(RP.datFecha,'%d/%m/%Y') AS datFecha, concat_ws(' ', E1.strNombre, E1.strApellidos) as responsable, E.numPreguntas, lngEstado\r\n                    FROM cabeceraencuesta E, tbempleados E1, tbresultados_esp R, tbrespuestas RP\r\n                    WHERE E.lngIdEmpleado = E1.lngIdEmpleado \r\n                    AND R.lngNumResp=RP.lngIdRespuesta\r\n                    AND R.lngIdEncuesta=E.lngId \r\n                    AND E.lngEstado <> 9\r\n                    AND R.lngNumResp NOT IN (SELECT NumResp FROM encuestasdescartadas)\r\n                 ";
     /*    
     
     				if ($visibilidad <>-1) 
     				   {
     				    $strSQL = $strSQL . " (U.lngPermiso = 2 OR U.lngPermiso = 1 OR R.strCodigoOficina = O.strCodigo OR R.strCodigoOficina IN (" . $visibilidad . ")) AND EResp.lngIdOficina = O.lngId " ;
     				   }else{ 
     					$strSQL = $strSQL . " (U.lngPermiso = 2 OR U.lngPermiso = 1 OR R.strCodigoOficina = O.strCodigo OR R.strCodigoOficina IN (SELECT lngVisibilidad FROM tbvisibilidad2 WHERE lngidEmpleado = U.lngIdEmpleado)) AND EResp.lngIdOficina = O.lngId " ;
     				   }
     				   $strSQL = $strSQL .  " AND U.lngIdEmpleado = EResp.lngIdEmpleado AND U.strUsuario = '" . $strUsuario . "'  AND R.lngStatus<>0";
     */
     //veo si hay datos en las fechas y añado los filtros
     if ($datAltaDesde != '') {
         $strSQL = $strSQL . " AND RP.datFecha >= '" . fecha_to_DATETIME($datAltaDesde) . "'";
     }
     if ($datAltaHasta != '') {
         $strSQL = $strSQL . " AND RP.datFecha <= '" . fecha_to_DATETIME_F($datAltaHasta) . "'";
     }
     //si no hubiese datos de fechas se filtra por los del año actual
     if ($datAltaDesde == '' && $datAltaHasta == '' && $strNumDesde == '' && $strNumHasta == '') {
         date_default_timezone_set('Europe/Madrid');
         $datAltaDesde = '01/01/' . date("Y");
         $strSQL = $strSQL . " AND RP.datFecha >= '" . fecha_to_DATETIME($datAltaDesde) . "'";
     }
     if ($strNumDesde != '') {
         $strSQL = $strSQL . " AND R.lngIdEncuesta >= '" . $strNumDesde . "'";
     }
     if ($strNumHasta != '') {
         $strSQL = $strSQL . " AND R.lngIdEncuesta <= '" . $strNumHasta . "'";
     }
     //$strSQL=$strSQL." ORDER BY E.lngId DESC, R.lngNumResp DESC";
     //	$strSQL=$strSQL." ORDER BY E.lngId ASC, R.lngNumResp ASC";
     //echo $strSQL;die;
     //hago la consulta que llevo en este momento (con o sin fechas)
     $db = new Db();
     //$db->conectar($this->getStrBD());
     $db->conectar($_SESSION['mapeo']);
     $stmt = $db->ejecutar($strSQL);
     $db->desconectar();
     //ahora guardo en un array los datos de la consulta
     //al guardar ahora compruebo si tengo datos en los filtros de encuesta y antes de guardar compruebo si
     //cumple esos filtros, sino no los guardo, sino hay filtro guardo la consulta tal cual
     $arcDoc = '';
     if ($stmt) {
         while ($row = mysql_fetch_array($stmt, MYSQL_ASSOC)) {
             //extraemos el numero de encuesta para poder comprobar que cumple los filtros
             //$numRecl=explode('/',$row['strencuesta']);
             //preparamos el numero ordenado primero el año y despues el numero
             //$numRecOrdenado=$numRecl[1].$numRecl[0];
             //ahora comprobamos si tenemos datos en 'desde', 'hasta' o 'desde' y 'hasta'
             //hay datos de 'desde' y 'hasta'
             if ($strNumDesde != '' && $strNumDesdeAnio != '' && $strNumHasta != '' && $strNumHastaAnio != '') {
                 //comprobamos si el nº encuesta esta entre estos los numeros
                 if ($desdeOrd <= $row['lngId'] && $hastaOrd >= $lngId) {
                     //si lo cumple lo incluimos en el listado
                     $this->guardarArrayListarRespuestas($arcDoc, $row);
                 }
             } else {
                 if ($strNumDesde != '' && $strNumDesdeAnio != '' && $strNumHasta == '' && $strNumHastaAnio == '') {
                     //comprobamos si el nº encuesta es igual o mayor que el 'desde'
                     if ($desdeOrd <= $lngId) {
                         //si lo cumple lo incluimos en el listado
                         $this->guardarArrayListarResuestas($arcDoc, $row);
                     }
                 } else {
                     if ($strNumDesde == '' && $strNumDesdeAnio == '' && $strNumHasta != '' && $strNumHastaAnio != '') {
                         //comprobamos si el nº encuesta es igual o menor que el 'hasta'
                         if ($hastaOrd >= $lngId) {
                             //si lo cumple lo incluimos en el listado
                             $this->guardarArrayListarRespuestas($arcDoc, $row);
                         }
                     } else {
                         //se incluye tal cual en el listado
                         $this->guardarArrayListarRespuestas($arcDoc, $row);
                     }
                 }
             }
         }
         //devuelvo el listado
         logger('traza', 'clsCADEnc.php-', 'clsCADEnc->ObtieneLista(' . $strUsuario . ',' . $strNumDesde . ',' . $strNumDesdeAnio . ',' . $strNumHasta . ',' . $strNumHastaAnio . ',' . $datAltaDesde . ',' . $datAltaHasta . '): Hay listado datos');
         //var_dump ($arcDoc);die;
         return $arcDoc;
     } else {
         //no hay datos
         logger('traza', 'clsCADEnc.php-', 'clsCADEnc->ObtieneLista(' . $strUsuario . ',' . $strNumDesde . ',' . $strNumDesdeAnio . ',' . $strNumHasta . ',' . $strNumHastaAnio . ',' . $datAltaDesde . ',' . $datAltaHasta . '): Esta vacio, no hay datos');
         return '';
     }
 }