Conheça as melhorias da versão 8.0, 8.1, 8.2!
Clique aqui para saber mais
Erro na query para gerar Relatorio ...
IM
Erro na query para gerar Relatorio  
 
  1. <?php
  2. //<fileHeader>
  3. //</fileHeader>
  4. class RelatorioTabular extends TPage
  5. {
  6. private $form; // form
  7. private $loaded;
  8. private static $database = 'clinica';
  9. private static $activeRecord = 'Agendamento';
  10. private static $primaryKey = 'id';
  11. private static $formName = 'formReport_Agendamento';
  12. //<classProperties>
  13. //</classProperties>
  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 BootstrapFormBuilder(self::$formName);
  23. // define the form title
  24. $this->form->setFormTitle("RelatorioTabular");
  25. $criteria_unidade_id = new TCriteria();
  26. $criteria_profissional = new TCriteria();
  27. $filterVar = TSession::getValue("userunitids");
  28. $criteria_unidade_id->add(new TFilter('id', 'in', $filterVar));
  29. $filterVar = Grupo::PROFISSIONAL;
  30. $criteria_profissional->add(new TFilter('id', 'in', "(SELECT pessoa_id FROM pessoa_grupo WHERE grupo_id in (SELECT id FROM grupo WHERE id = '{$filterVar}') )"));
  31. $unidade_id = new TDBCombo('unidade_id', 'clinica', 'SystemUnit', 'id', '{name}','name asc' , $criteria_unidade_id );
  32. $profissional = new TDBCombo('profissional', 'clinica', 'Pessoa', 'id', '{nome}','nome asc' , $criteria_profissional );
  33. $data_ini = new TDate('data_ini');
  34. $data_fim = new TDate('data_fim');
  35. $data_ini->setDatabaseMask('yyyy-mm-dd');
  36. $data_fim->setDatabaseMask('yyyy-mm-dd');
  37. $data_ini->setMask('dd/mm/yyyy');
  38. $data_fim->setMask('dd/mm/yyyy');
  39. $data_ini->setSize(160);
  40. $data_fim->setSize(160);
  41. $unidade_id->setSize('97%');
  42. $profissional->setSize('97%');
  43. $row1 = $this->form->addFields([new TLabel("Unidade:", null, '14px', null, '100%')],[$unidade_id],[new TLabel("Profissional:", null, '14px', null)],[$profissional]);
  44. $row2 = $this->form->addFields([new TLabel("Data inicial:", null, '14px', null)],[$data_ini],[new TLabel("Data final:", null, '14px', null)],[$data_fim]);
  45. // keep the form filled during navigation with session data
  46. $this->form->setData( TSession::getValue(__CLASS__.'_filter_data') );
  47. $btn_ongeneratehtml = $this->form->addAction("Gerar HTML", new TAction([$this, 'onGenerateHtml']), 'fa:code #ffffff');
  48. $btn_ongeneratehtml->addStyleClass('btn-primary');
  49. $btn_ongeneratepdf = $this->form->addAction("Gerar PDF", new TAction([$this, 'onGeneratePdf']), 'fa:file-pdf-o #d44734');
  50. $btn_ongeneratexls = $this->form->addAction("Gerar XLS", new TAction([$this, 'onGenerateXls']), 'fa:file-excel-o #00a65a');
  51. $btn_ongeneratertf = $this->form->addAction("Gerar RTF", new TAction([$this, 'onGenerateRtf']), 'fa:file-text-o #324bcc');
  52. // vertical box container
  53. $container = new TVBox;
  54. $container->style = 'width: 100%';
  55. $container->add(TBreadCrumb::create(["Gráficos","Gráficos de ajustes"]));
  56. $container->add($this->form);
  57. parent::add($container);
  58. }
  59. //<generated-FormAction-onGenerateHtml>
  60. public function onGenerateHtml($param = null)
  61. {
  62. $this->onGenerate('html');
  63. }//</end>
  64. //</generated-FormAction-onGenerateHtml>
  65. //<generated-FormAction-onGeneratePdf>
  66. public function onGeneratePdf($param = null)
  67. {
  68. $this->onGenerate('pdf');
  69. }//</end>
  70. //</generated-FormAction-onGeneratePdf>
  71. //<generated-FormAction-onGenerateXls>
  72. public function onGenerateXls($param = null)
  73. {
  74. $this->onGenerate('xls');
  75. }//</end>
  76. //</generated-FormAction-onGenerateXls>
  77. //<generated-FormAction-onGenerateRtf>
  78. public function onGenerateRtf($param = null)
  79. {
  80. $this->onGenerate('rtf');
  81. }//</end>
  82. //</generated-FormAction-onGenerateRtf>
  83. /**
  84. * Register the filter in the session
  85. */
  86. public function getFilters()
  87. {
  88. // get the search form data
  89. $data = $this->form->getData();
  90. $filters = [];
  91. TSession::setValue('filter_data', NULL);
  92. if ($data->unidade_id)
  93. {
  94. $filters['unidade_id'] = $data->unidade_id;// create the filter
  95. };
  96. if (($data->data_ini !== '') AND ($data->data_fim !== ''))
  97. {
  98. $filters['data_ini'] = $data->data_ini;
  99. $filters['data_fim'] = $data->data_fim;
  100. }
  101. // fill the form with data again
  102. $this->form->setData($data);
  103. // keep the search data in the session
  104. TSession::setValue('filter_data', $filters);
  105. return $filters;
  106. }
  107. public function onGenerate($format)
  108. {
  109. try
  110. {
  111. $filters = $this->getFilters();
  112. // open a transaction with database 'clinica'
  113. TTransaction::open('clinica');
  114. $dt_ini = $filters['data_ini'];
  115. $dt_fim = $filters['data_fim'];
  116. $sql = "create temporary table a (index (data))
  117. SELECT count(id) qtd, date(dt_clinica) as data FROM movto_clinico
  118. where dt_clinica between '$dt_ini' and '$dt_fim' group by dt_clinica;
  119. create temporary table b (index (data))
  120. SELECT count(id) cad, date(dt_ativacao) as data FROM pessoa
  121. where dt_ativacao between '$dt_ini' and '$dt_fim' group by dt_ativacao;
  122. create temporary table c (index (data))
  123. SELECT count(id) age, date(start_time) as data FROM agendamento
  124. where date(start_time) between '$dt_ini' and '$dt_fim' group by date(start_time);
  125. create temporary table d (index (data))
  126. SELECT sum(valorparcial) sum, date(dt_pagamento) as data FROM movto_financeiro
  127. where dt_pagamento is not NULL and dt_pagamento between '$dt_ini' and '$dt_fim' group by dt_pagamento;
  128. select a.*, b.cad, c.age, d.sum
  129. from a left outer join b using (data) left outer join c using (data) left outer join d using (data)";
  130. $conn = TTransaction::get();
  131. $objects = $conn->query($sql);
  132. // load the objects according to criteria
  133. //$objects = $repository->load($criteria, FALSE);
  134. if ($objects)
  135. {
  136. $widths = array(200,200,200,200,200,200,200,200);
  137. switch ($format)
  138. {
  139. case 'html':
  140. $tr = new TTableWriterHTML($widths);
  141. break;
  142. case 'xls':
  143. $tr = new TTableWriterXLS($widths);
  144. break;
  145. case 'pdf':
  146. $tr = new TTableWriterPDF($widths, 'L');
  147. break;
  148. case 'rtf':
  149. if (!class_exists('PHPRtfLite_Autoloader'))
  150. {
  151. PHPRtfLite::registerAutoloader();
  152. }
  153. $tr = new TTableWriterRTF($widths, 'L');
  154. break;
  155. }
  156. if (!empty($tr))
  157. {
  158. // create the document styles
  159. $tr->addStyle('title', 'Helvetica', '10', 'B', '#000000', '#dbdbdb');
  160. $tr->addStyle('datap', 'Arial', '10', '', '#333333', '#f0f0f0');
  161. $tr->addStyle('datai', 'Arial', '10', '', '#333333', '#ffffff');
  162. $tr->addStyle('header', 'Helvetica', '16', 'B', '#5a5a5a', '#6B6B6B');
  163. $tr->addStyle('footer', 'Helvetica', '10', 'B', '#5a5a5a', '#A3A3A3');
  164. $tr->addStyle('break', 'Helvetica', '10', 'B', '#ffffff', '#9a9a9a');
  165. $tr->addStyle('total', 'Helvetica', '10', 'I', '#000000', '#c7c7c7');
  166. $tr->addStyle('breakTotal', 'Helvetica', '10', 'I', '#000000', '#c6c8d0');
  167. // add titles row
  168. $tr->addRow();
  169. $tr->addCell("Data", 'left', 'title');
  170. $tr->addCell("Quantidade de retorno", 'left', 'title');
  171. $tr->addCell("Pacientes novos", 'left', 'title');
  172. $tr->addCell("Pessoas atendidas", 'left', 'title');
  173. $tr->addCell("Valor recebido", 'left', 'title');
  174. $grandTotal = [];
  175. $breakTotal = [];
  176. $breakValue = null;
  177. $firstRow = true;
  178. // controls the background filling
  179. $colour = false;
  180. while ($linha = $objects->fetch(PDO::FETCH_OBJ))
  181. {
  182. $style = $colour ? 'datap' : 'datai';
  183. $firstRow = false;
  184. $tr->addRow();
  185. $tr->addCell($object->data, 'left', $style);
  186. $tr->addCell($object->qtd, 'left', $style);
  187. $tr->addCell($object->cad, 'left', $style);
  188. $tr->addCell($object->age, 'left', $style);
  189. $tr->addCell($object->sum, 'left', $style);
  190. $colour = !$colour;
  191. };
  192. var_dump('ate aqui');
  193. $file = 'report_'.uniqid().".{$format}";
  194. // stores the file
  195. if (!file_exists("app/output/{$file}") || is_writable("app/output/{$file}"))
  196. {
  197. $tr->save("app/output/{$file}");
  198. }
  199. else
  200. {
  201. throw new Exception(_t('Permission denied') . ': ' . "app/output/{$file}");
  202. }
  203. parent::openFile("app/output/{$file}");
  204. // shows the success message
  205. new TMessage('info', _t('Report generated. Please, enable popups'));
  206. }
  207. }
  208. else
  209. {
  210. new TMessage('error', _t('No records found'));
  211. }
  212. // close the transaction
  213. TTransaction::close();
  214. }
  215. catch (Exception $e) // in case of exception
  216. {
  217. // shows the exception error message
  218. new TMessage('error', $e->getMessage());
  219. // undo all pending operations
  220. TTransaction::rollback();
  221. }
  222. }
  223. public function onShow($param = null)
  224. {
  225. //<onShow>
  226. //</onShow>
  227. }
  228. //</hideLine> <addUserFunctionsCode/>
  229. //<userCustomFunctions>
  230. //</userCustomFunctions>
  231. }
  232. ?>

Pessoal já tentei de tudo e não consigo gerar o relatorio ... dá erro no for each

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


RB

Linha 37, 39 esta estranho ....

37 - $filterVar = TSession::getValue("userunitids");

39 - $filterVar = Grupo::PROFISSIONAL;
IM

problema está o=no while .,.
Linha 229 em diante
RB


 
  1. <?php
  2. //Tenta tira o ponto e virgula 244
  3. // };
  4. }
  5. ?>