Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Filtro por período inicial e final Boa noite pessoal, Preciso fazer um filtro onde eu informo data inicial e data final, onde é comparado com a data de vencimento para listar os dados através da função onSearch(). O problema é que só lista os dados se eu colocar na mão, por exemplo: ...
FS
Filtro por período inicial e final  
Fechado
Boa noite pessoal,
Preciso fazer um filtro onde eu informo data inicial e data final, onde é comparado com a data de vencimento para listar os dados através da função onSearch().
O problema é que só lista os dados se eu colocar na mão, por exemplo:

  1. <?php
  2.   if ($data->dtinicio){
  3.             $filter = new TFilter('vencimento''=''2015/10/26'); // create the filter
  4.             TSession::setValue('ParcelasList_filter_dtinicio',   $filter); // stores the filter in the session
  5.         }
  6. ?>


Se eu colocar pra filtrar chamando pela variável conforme abaixo, não lista nada, retornando em branco. 99,9% de chance de eu estar chamando a variável da forma errada, lembrando que dtinicial e dtfinal não tem no banco de dados, servem somente para o filtro.

  1. <?php
  2.         if ($data->dtfim){
  3.             $filter = new TFilter('vencimento''<='$data->dtfim); // create the filter
  4.             TSession::setValue('ParcelasList_filter_dtfim',   $filter); // stores the filter in the session
  5.         }
  6. ?>


Obrigado.


Esta é a função onSearch() completa.

  1. <?php
  2. function onSearch()
  3.     {
  4.         // get the search form data
  5.         $data $this->form->getData();
  6.         
  7.         // clear session filters
  8.         TSession::setValue('ParcelasList_filter_nome_aluno',   NULL);
  9.         TSession::setValue('ParcelasList_filter_dtinicio',   NULL);
  10.         TSession::setValue('ParcelasList_filter_dtfim',   NULL);
  11.         if (isset($data->nome_aluno) AND ($data->nome_aluno)) {
  12.             $filter = new TFilter('nome_aluno''like'"%{$data->nome_aluno}%"); // create the filter
  13.             TSession::setValue('ParcelasList_filter_nome_aluno',   $filter); // stores the filter in the session
  14.         }
  15.         if ($data->dtinicio){
  16.             $filter = new TFilter('vencimento''=''2015/10/26'); // create the filter
  17.             TSession::setValue('ParcelasList_filter_dtinicio',   $filter); // stores the filter in the session
  18.         }
  19.         if ($data->dtfim){
  20.             $filter = new TFilter('vencimento''<='$data->dtfim); // create the filter
  21.             TSession::setValue('ParcelasList_filter_dtfim',   $filter); // stores the filter in the session
  22.         }
  23.         
  24.         // fill the form with data again
  25.         $this->form->setData($data);
  26.         
  27.         // keep the search data in the session
  28.         TSession::setValue('Parcelas_filter_data'$data);
  29.         
  30.         $param=array();
  31.         $param['offset']    =0;
  32.         $param['first_page']=1;
  33.         $this->onReload($param);
  34.     }
  35. ?>




Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (2)


IF

Olá Fabiano, converta a data para o formato americano antes de enviar para o filtro:

  1. <?php
  2.  $data->dtfim TDate::date2us($data->dtfim);
  3.  $filter = new TFilter('vencimento''<='$data->dtfim);
  4.  
  5. ?>
FS

Deu certo Ivan,
Muito obrigado!!!