Exemplo n.º 1
0
 public function testDoCountFromObj()
 {
     $db = new clsBanco();
     $db->Conecta();
     $obj = new clsPmieducarClienteSuspensao();
     $this->assertNotEquals(TRUE, is_null($db->doCountFromObj($obj)));
 }
 /**
  * Retorna uma lista filtrada de acordo com os argumentos.
  *
  * @return Array
  */
 public function listaCompleta($int_cod_cliente = NULL, $int_ref_usuario_exc = NULL, $int_ref_usuario_cad = NULL, $int_ref_idpes = NULL, $int_login = NULL, $str_senha = NULL, $date_data_cadastro_ini = NULL, $date_data_cadastro_fim = NULL, $date_data_exclusao_ini = NULL, $date_data_exclusao_fim = NULL, $int_ativo = 1, $str_nm_cliente = NULL, $str_suspenso = NULL, $int_cod_cliente_tipo = NULL, $int_cod_escola = NULL, $int_cod_biblioteca = NULL, $int_cod_instituicao = NULL)
 {
     $tab_adicional = '';
     $condicao = '';
     $camp_adicional = '';
     // Executa filtragem por clientes suspensos somente quando houver registros na tabela
     $clienteSuspenso = new clsPmieducarClienteSuspensao();
     $db = new clsBanco();
     // Se suspenso não for nulo e existirem cliente suspensos, seleciona-os
     // quando ainda estiverem no prazo de suspensão
     if ($db->doCountFromObj($clienteSuspenso) > 0) {
         if (!is_null($str_suspenso)) {
             $camp_adicional .= ', pmieducar.cliente_suspensao cs ';
             $condicao .= ' AND c.cod_cliente = cs.ref_cod_cliente AND
                        (cs.data_suspensao < current_date - cs.dias)';
         } else {
             $camp_adicional .= ', pmieducar.cliente_suspensao cs ';
             $condicao .= ' AND (c.cod_cliente <> cs.ref_cod_cliente OR
                          (cs.data_suspensao > current_date - cs.dias))';
         }
     }
     $sql1 = "\n            SELECT\n              c.cod_cliente,\n              c.ref_idpes,\n              c.ref_usuario_cad,\n              c.login,\n              p.nome,\n              ct.nm_tipo,\n              ct.cod_cliente_tipo,\n              b.nm_biblioteca,\n              b.cod_biblioteca,\n              e.cod_escola as cod_escola,\n              i.cod_instituicao,\n              (SELECT 'S'::text\n                FROM pmieducar.cliente_suspensao cs\n                WHERE cs.ref_cod_cliente = c.cod_cliente\n                AND cs.data_liberacao IS NULL) AS id_suspensao\n            FROM\n              pmieducar.cliente                c,\n              pmieducar.cliente_tipo_cliente ctc,\n              pmieducar.cliente_tipo          ct,\n              pmieducar.biblioteca             b,\n              pmieducar.escola                 e,\n              pmieducar.instituicao            i,\n              cadastro.pessoa                  p{$camp_adicional}\n            WHERE\n              c.cod_cliente             = ctc.ref_cod_cliente\n              AND ct.cod_cliente_tipo   = ctc.ref_cod_cliente_tipo\n              AND b.cod_biblioteca      = ct.ref_cod_biblioteca\n              AND e.cod_escola          = b.ref_cod_escola\n              AND i.cod_instituicao     = b.ref_cod_instituicao\n              AND e.ref_cod_instituicao = i.cod_instituicao{$condicao}\n              AND p.idpes               = c.ref_idpes\n              AND c.ativo               = '{$int_ativo}'\n              AND ctc.ativo             = '{$int_ativo}'";
     $sql2 = "\n            SELECT\n              c.cod_cliente,\n              c.ref_idpes,\n              c.ref_usuario_cad,\n              c.login,\n              p.nome,\n              ct.nm_tipo,\n              ct.cod_cliente_tipo,\n              b.nm_biblioteca,\n              b.cod_biblioteca,\n              null as cod_escola,\n              i.cod_instituicao,\n              (SELECT 'S'::text\n                FROM pmieducar.cliente_suspensao cs\n                WHERE cs.ref_cod_cliente = c.cod_cliente\n                AND cs.data_liberacao IS NULL) AS id_suspensao\n            FROM\n              pmieducar.cliente                c,\n              pmieducar.cliente_tipo_cliente ctc,\n              pmieducar.cliente_tipo          ct,\n              pmieducar.biblioteca             b,\n              pmieducar.instituicao            i,\n              cadastro.pessoa                  p{$camp_adicional}\n            WHERE c.cod_cliente         = ctc.ref_cod_cliente\n              AND ct.cod_cliente_tipo   = ctc.ref_cod_cliente_tipo\n              AND b.cod_biblioteca      = ct.ref_cod_biblioteca\n              AND i.cod_instituicao     = b.ref_cod_instituicao\n              AND b.ref_cod_escola      IS NULL\n              AND ct.ref_cod_biblioteca = b.cod_biblioteca{$condicao}\n              AND p.idpes               = c.ref_idpes\n              AND c.ativo               = '{$int_ativo}'\n              AND ctc.ativo             = '{$int_ativo}'";
     $filtros = '';
     $whereAnd = ' AND ';
     if (is_numeric($int_cod_cliente)) {
         $filtros .= "{$whereAnd} c.cod_cliente = '{$int_cod_cliente}'";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_ref_usuario_exc)) {
         $filtros .= "{$whereAnd} c.ref_usuario_exc = '{$int_ref_usuario_exc}'";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_ref_usuario_cad)) {
         $filtros .= "{$whereAnd} c.ref_usuario_cad = '{$int_ref_usuario_cad}'";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_ref_idpes)) {
         $filtros .= "{$whereAnd} c.ref_idpes = '{$int_ref_idpes}'";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_login)) {
         $filtros .= "{$whereAnd} c.login = '******'";
         $whereAnd = " AND ";
     }
     if (is_string($str_senha)) {
         $filtros .= "{$whereAnd} c.senha = '{$str_senha}'";
         $whereAnd = " AND ";
     }
     if (is_string($date_data_cadastro_ini)) {
         $filtros .= "{$whereAnd} c.data_cadastro >= '{$date_data_cadastro_ini}'";
         $whereAnd = " AND ";
     }
     if (is_string($date_data_cadastro_fim)) {
         $filtros .= "{$whereAnd} c.data_cadastro <= '{$date_data_cadastro_fim}'";
         $whereAnd = " AND ";
     }
     if (is_string($date_data_exclusao_ini)) {
         $filtros .= "{$whereAnd} c.data_exclusao >= '{$date_data_exclusao_ini}'";
         $whereAnd = " AND ";
     }
     if (is_string($date_data_exclusao_fim)) {
         $filtros .= "{$whereAnd} c.data_exclusao <= '{$date_data_exclusao_fim}'";
         $whereAnd = " AND ";
     }
     if (is_null($int_ativo) || $int_ativo) {
         $filtros .= "{$whereAnd} c.ativo = '1'";
         $whereAnd = " AND ";
     } else {
         $filtros .= "{$whereAnd} c.ativo = '0'";
         $whereAnd = " AND ";
     }
     if (is_string($str_nm_cliente)) {
         $filtros .= "{$whereAnd} p.nome LIKE '%{$str_nm_cliente}%'";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_cod_cliente_tipo)) {
         $filtros .= "{$whereAnd} ct.cod_cliente_tipo = '{$int_cod_cliente_tipo}'";
         $whereAnd = " AND ";
     }
     if (is_array($int_cod_biblioteca)) {
         $array_biblioteca = implode(", ", $int_cod_biblioteca);
         $filtros .= "{$whereAnd} b.cod_biblioteca IN ({$array_biblioteca})";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_cod_biblioteca)) {
         $filtros .= "{$whereAnd} b.cod_biblioteca = '{$int_cod_biblioteca}'";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_cod_escola)) {
         $filtros .= "{$whereAnd} e.cod_escola = '{$int_cod_escola}'";
         $whereAnd = " AND ";
     }
     if (is_numeric($int_cod_instituicao)) {
         $filtros .= "{$whereAnd} i.cod_instituicao = '{$int_cod_instituicao}'";
         $whereAnd = " AND ";
     }
     if (is_string($str_suspenso)) {
         $filtros .= "{$whereAnd} cs.data_liberacao IS NULL";
         $whereAnd = " AND ";
     }
     $db = new clsBanco();
     $resultado = array();
     $sql1 .= $filtros;
     $sql2 .= $filtros;
     if (is_numeric($int_cod_escola)) {
         $this->_total = $db->CampoUnico("SELECT count(0) FROM ({$sql1}) AS SUBQUERY");
     } else {
         $this->_total = $db->CampoUnico("SELECT count(0) FROM (" . $sql1 . " UNION " . $sql2 . ") AS SUBQUERY");
     }
     // Aplica ordenação e limite
     $sql2 .= $this->getOrderby() . $this->getLimite();
     if (is_numeric($int_cod_escola)) {
         $sql = $sql1;
     } else {
         $sql = $sql1 . ' UNION ' . $sql2;
     }
     $db->Consulta($sql);
     while ($db->ProximoRegistro()) {
         $tupla = $db->Tupla();
         $tupla["_total"] = $this->_total;
         $resultado[] = $tupla;
     }
     if (count($resultado) > 0) {
         return $resultado;
     }
     return FALSE;
 }