Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Apresentar no formulário de consulta a data em dd/mm/yyyy Bom dia, olha eu aqui de novo, ontem consegui a ajuda de vocês para colocar a data no formato desejado, porém ao realizar a consulta o campo "Data agendada" volta para o formato 'yyyy-mm-dd', eu não sei onde devo fazer a conversão dele. Segue tela e código: ...
RF
Apresentar no formulário de consulta a data em dd/mm/yyyy  
Fechado
Bom dia, olha eu aqui de novo, ontem consegui a ajuda de vocês para colocar a data no formato desejado, porém ao realizar a consulta o campo "Data agendada" volta para o formato 'yyyy-mm-dd', eu não sei onde devo fazer a conversão dele. Segue tela e código:

  1. <?php
  2. /**
  3.  * ProspeccaoList Listing
  4.  * @author  <your name here>
  5.  */
  6. class ProspeccaoList extends TPage
  7. {
  8.     private $form// form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $formgrid;
  12.     private $loaded;
  13.     private $deleteButton;
  14.     
  15.     /**
  16.      * Class constructor
  17.      * Creates the page, the form and the listing
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         // creates the form
  24.         $this->form = new TQuickForm('form_search_Prospeccao');
  25.         $this->form->class 'tform'// change CSS class
  26.         
  27.         $this->form->style 'display: table;width:100%'// change style
  28.         //$this->form->setFormTitle('Pesquisa conforme o filtro');
  29.         
  30.         // create the form fields
  31.         $customer_cnpj  = new TEntry('customer_cnpj');
  32.         $rasocial       = new TEntry('rasocial');
  33.         $acompanhar     = new TCombo('acompanhar');
  34.         $proximocontato = new TDate('proximocontato');
  35.         //Mascara dos campos
  36.         $customer_cnpj   ->setMask('99.999.999/9999-99');
  37.         $proximocontato  ->setMask('dd/mm/yyyy');
  38.         
  39.         //Itens do campo acompanhar
  40.         $itemGender = array();//opções
  41.         $itemGender['Sim'] = 'Sim';
  42.         $itemGender['Não'] = 'Não';
  43.         // adiciona as opções na lista
  44.         $acompanhar->addItems($itemGender);
  45.         
  46.         // add the fields
  47.         $this->form->addQuickField('C.N.P.J:'$customer_cnpj,  200 );
  48.         $this->form->addQuickField('Razão Social:'$rasocial,  200 );
  49.         $this->form->addQuickField('Agendado como Sim ou Não:'$acompanhar,  200 );
  50.         $this->form->addQuickField('Data agendada:'$proximocontato,  180 );
  51.      
  52.         // keep the form filled during navigation with session data
  53.         $this->form->setDataTSession::getValue('Prospeccao_filter_data') );
  54.         
  55.         // add the search form actions
  56.         $this->form->addQuickAction(_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  57.         $this->form->addQuickAction(_t('New'),  new TAction(array('ProspeccaoForm''onEdit')), 'bs:plus-sign green');
  58.         
  59.         // creates a Datagrid
  60.         $this->datagrid = new TDataGrid;
  61.         
  62.         $this->datagrid->style 'width: 100%';
  63.         $this->datagrid->setHeight(300);
  64.         
  65.         // creates the datagrid columns
  66.         $column_id = new TDataGridColumn('id''N.''right');
  67.         $column_customer_cnpj = new TDataGridColumn('customer_cnpj''CNPJ''left');
  68.         $column_rasocial = new TDataGridColumn('rasocial''R. Social''left');
  69.         $column_telefone = new TDataGridColumn('telefone''Telefone''left');
  70.         $column_email = new TDataGridColumn('email''E-mail''left');
  71.         $column_acompanhar = new TDataGridColumn('acompanhar''Acompanhar''left');
  72.         $column_proximocontato = new TDataGridColumn('proximocontato''Próximo contato''left');
  73.         
  74.      
  75.         // add the columns to the DataGrid
  76.         $this->datagrid->addColumn($column_id);
  77.         $this->datagrid->addColumn($column_customer_cnpj);
  78.         $this->datagrid->addColumn($column_rasocial);
  79.         $this->datagrid->addColumn($column_telefone);
  80.         $this->datagrid->addColumn($column_email);
  81.         $this->datagrid->addColumn($column_acompanhar);
  82.         $this->datagrid->addColumn($column_proximocontato);
  83.         // create EDIT action
  84.         $action_edit = new TDataGridAction(array('ProspeccaoForm''onEdit'));
  85.         $action_edit->setUseButton(TRUE);
  86.         $action_edit->setButtonClass('btn btn-default');
  87.         //$action_edit->setLabel(_t('Edit'));
  88.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  89.         $action_edit->setField('id');
  90.         $this->datagrid->addAction($action_edit);
  91.         
  92.         // create DELETE action
  93.         $action_del = new TDataGridAction(array($this'onDelete'));
  94.         $action_del->setUseButton(TRUE);
  95.         $action_del->setButtonClass('btn btn-default');
  96.         //$action_del->setLabel(_t('Delete'));
  97.         $action_del->setImage('fa:trash-o red fa-lg');
  98.         $action_del->setField('id');
  99.         $this->datagrid->addAction($action_del);
  100.         
  101.         // create the datagrid model
  102.         $this->datagrid->createModel();
  103.         
  104.         // creates the page navigation
  105.         $this->pageNavigation = new TPageNavigation;
  106.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  107.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  108.         
  109.         // Sub menu bonito
  110.         $vbox = new TVBox;
  111.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  112.         $vbox->add($this->form);
  113.         $vbox->style 'width: 100%';       
  114.         $vbox->add($this->datagrid);
  115.         $vbox->add($this->pageNavigation);
  116.         parent::add($vbox);  
  117.     }
  118.     
  119.     /**
  120.      * Inline record editing
  121.      * @param $param Array containing:
  122.      *              key: object ID value
  123.      *              field name: object attribute to be updated
  124.      *              value: new attribute content 
  125.      */
  126.     public function onInlineEdit($param)
  127.     {
  128.         try
  129.         {
  130.             // get the parameter $key
  131.             $field $param['field'];
  132.             $key   $param['key'];
  133.             $value $param['value'];
  134.             
  135.             TTransaction::open('samples'); // open a transaction with database
  136.             $object = new Prospeccao($key); // instantiates the Active Record
  137.             $object->proximocontato=TDate::date2br($object->proximocontato);
  138.             $object->{$field} = $value;
  139.             $object->store(); // update the object in the database
  140.             TTransaction::close(); // close the transaction
  141.             
  142.             $this->onReload($param); // reload the listing
  143.             new TMessage('info'"Record Updated");
  144.         }
  145.         catch (Exception $e// in case of exception
  146.         {
  147.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  148.             TTransaction::rollback(); // undo all pending operations
  149.         }
  150.     }
  151.     
  152.     /**
  153.      * Register the filter in the session
  154.      */
  155.     public function onSearch()
  156.     {
  157.         // get the search form data
  158.         $data $this->form->getData();
  159.         
  160.         // clear session filters
  161.         TSession::setValue('ProspeccaoList_filter_customer_cnpj',   NULL);
  162.         TSession::setValue('ProspeccaoList_filter_rasocial',   NULL);
  163.         TSession::setValue('ProspeccaoList_filter_acompanhar',   NULL);
  164.         TSession::setValue('ProspeccaoList_filter_proximocontato',   NULL);
  165.         if (isset($data->customer_cnpj) AND ($data->customer_cnpj)) {
  166.             $filter = new TFilter('customer_cnpj''like'"%{$data->customer_cnpj}%"); // create the filter
  167.             TSession::setValue('ProspeccaoList_filter_customer_cnpj',   $filter); // stores the filter in the session
  168.         }
  169.         if (isset($data->rasocial) AND ($data->rasocial)) {
  170.             $filter = new TFilter('rasocial''like'"%{$data->rasocial}%"); // create the filter
  171.             TSession::setValue('ProspeccaoList_filter_rasocial',   $filter); // stores the filter in the session
  172.         }
  173.         if (isset($data->acompanhar) AND ($data->acompanhar)) {
  174.             $filter = new TFilter('acompanhar''like'"%{$data->acompanhar}%"); // create the filter
  175.             TSession::setValue('ProspeccaoList_filter_acompanhar',   $filter); // stores the filter in the session
  176.         }
  177.         if (isset($data->proximocontato) AND ($data->proximocontato)) {
  178.             $data->proximocontato TDate::date2us($data->proximocontato);//Muda para o formato USA
  179.             $filter = new TFilter('proximocontato''like'"%{$data->proximocontato}%"); // create the filter
  180.             TSession::setValue('ProspeccaoList_filter_proximocontato',   $filter); // stores the filter in the session
  181.         }
  182.         
  183.         // fill the form with data again
  184.         $this->form->setData($data);
  185.         
  186.         // keep the search data in the session
  187.         TSession::setValue('Prospeccao_filter_data'$data);
  188.         
  189.         $param=array();
  190.         $param['offset']    =0;
  191.         $param['first_page']=1;
  192.         $this->onReload($param);
  193.     }
  194.     
  195.     /**
  196.      * Load the datagrid with data
  197.      */
  198.     public function onReload($param NULL)
  199.     {
  200.         try
  201.         {
  202.             // open a transaction with database 'samples'
  203.             TTransaction::open('samples');
  204.             
  205.             // creates a repository for Prospeccao
  206.             $repository = new TRepository('Prospeccao');
  207.             $limit 10;
  208.             // creates a criteria
  209.             $criteria = new TCriteria;
  210.             
  211.             // default order
  212.             if (empty($param['order']))
  213.             {
  214.                 $param['order'] = 'id';
  215.                 $param['direction'] = 'asc';
  216.             }
  217.             
  218.             $criteria->setProperties($param); // order, offset
  219.             $criteria->setProperty('limit'$limit);
  220.             
  221.             
  222.             if (TSession::getValue('ProspeccaoList_filter_customer_cnpj')) {
  223.                 $criteria->add(TSession::getValue('ProspeccaoList_filter_customer_cnpj')); // add the session filter
  224.             }
  225.             if (TSession::getValue('ProspeccaoList_filter_rasocial')) {
  226.                 $criteria->add(TSession::getValue('ProspeccaoList_filter_rasocial')); // add the session filter
  227.             }
  228.             if (TSession::getValue('ProspeccaoList_filter_acompanhar')) {
  229.                 $criteria->add(TSession::getValue('ProspeccaoList_filter_acompanhar')); // add the session filter
  230.             }
  231.             if (TSession::getValue('ProspeccaoList_filter_proximocontato')) {
  232.                 $criteria->add(TSession::getValue('ProspeccaoList_filter_proximocontato')); // add the session filter
  233.             }
  234.             
  235.             // load the objects according to criteria
  236.             $objects $repository->load($criteriaFALSE);
  237.             
  238.             if (is_callable($this->transformCallback))
  239.             {
  240.                 call_user_func($this->transformCallback$objects$param);
  241.             }
  242.             
  243.             //Converte a data em português
  244.             if ($objects)
  245.             {
  246.                 // iterate the collection of active records
  247.                 foreach ($objects as $object)
  248.                 {
  249.                     $object->proximocontato TDate::date2br($object->proximocontato);
  250.                     $this->datagrid->addItem($object);
  251.                 }
  252.             }
  253.                   
  254.             // reset the criteria for record count
  255.             $criteria->resetProperties();
  256.             $count$repository->count($criteria);
  257.             
  258.             $this->pageNavigation->setCount($count); // count of records
  259.             $this->pageNavigation->setProperties($param); // order, page
  260.             $this->pageNavigation->setLimit($limit); // limit
  261.             
  262.             // close the transaction
  263.             TTransaction::close();
  264.             $this->loaded true;
  265.         }
  266.         catch (Exception $e// in case of exception
  267.         {
  268.             // shows the exception error message
  269.             new TMessage('error'$e->getMessage());
  270.             // undo all pending operations
  271.             TTransaction::rollback();
  272.         }
  273.     }
  274.     
  275.     /**
  276.      * Ask before deletion
  277.      */
  278.     public function onDelete($param)
  279.     {
  280.         // define the delete action
  281.         $action = new TAction(array($this'Delete'));
  282.         $action->setParameters($param); // pass the key parameter ahead
  283.         
  284.         // shows a dialog to the user
  285.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  286.     }
  287.     
  288.     /**
  289.      * Delete a record
  290.      */
  291.     public function Delete($param)
  292.     {
  293.         try
  294.         {
  295.             $key=$param['key']; // get the parameter $key
  296.             TTransaction::open('samples'); // open a transaction with database
  297.             $object = new Prospeccao($keyFALSE); // instantiates the Active Record
  298.             $object->delete(); // deletes the object from the database
  299.             TTransaction::close(); // close the transaction
  300.             $this->onReload$param ); // reload the listing
  301.             new TMessage('info'AdiantiCoreTranslator::translate('Record deleted')); // success message
  302.         }
  303.         catch (Exception $e// in case of exception
  304.         {
  305.             new TMessage('error'$e->getMessage()); // shows the exception error message
  306.             TTransaction::rollback(); // undo all pending operations
  307.         }
  308.     }
  309.     /**
  310.      * method show()
  311.      * Shows the page
  312.      */
  313.     public function show()
  314.     {
  315.         // check if the datagrid is already loaded
  316.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  317.         {
  318.             if (func_num_args() > 0)
  319.             {
  320.                 $this->onReloadfunc_get_arg(0) );
  321.             }
  322.             else
  323.             {
  324.                 $this->onReload();
  325.             }
  326.         }
  327.         parent::show();
  328.     }
  329. }

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (4)


IF

Robson, nessa parte do código, tenta voltar a data para o formato br:
  1. <?php
  2. if (isset($data->proximocontato) AND ($data->proximocontato)) {
  3.             $data->proximocontato TDate::date2us($data->proximocontato);//Muda para o formato USA
  4.             $filter = new TFilter('proximocontato''like'"%{$data->proximocontato}%"); // create the filter
  5.             $data->proximocontato TDate::datebr($data->proximocontato);  // Aqui vc muda para o formato br
  6.             TSession::setValue('ProspeccaoList_filter_proximocontato',   $filter); // stores the filter in the session
  7.         }
  8. ?>
RF

Boa noite Ivan, muito obrigado, mais uma barreira superada, tenho ainda três pontos nebulosos mas isso não vem ao caso deste post, primeiro vou tentar realizar o trabalho sozinho com base no conceito transmitido.
Fico realmente muito feliz com o suporte encontrado neste site, isso trás segurança e credibilidade para a ferramenta. E também para o meu futuro, pois o sonho de criar um sistema de transporte está cada dia mais perto. Obrigado.
IF

Blz, conte sempre com a comunidade. Abraço.
PD

www.adianti.com.br/forum/pt/view_2287?conversao-de-datas-e-valores-m