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

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 (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