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




Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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. ?>
FS

Deu certo Ivan,
Muito obrigado!!!