Geração de PDF com mais de uma Tabela(Repository)! Olá a todos! Estou necessitado de ajuda. Ja tenho os livros do adianti e tenho acompanhado os projetos. Estou PRECISANDO realizar a geração de um relatorio em pdf com BASE na consulta de 06 tabelas mas nao precisa de INNER JOIN. Vou gerar um PDF com os dados do paciente e abaixo preciso exibir o resultado dos exames que foram cadastrados cada um em uma tabela diferente (TABELA PACIENTE, T...
AJ
Geração de PDF com mais de uma Tabela(Repository)!  
Olá a todos! Estou necessitado de ajuda. Ja tenho os livros do adianti e tenho acompanhado os projetos.

Estou PRECISANDO realizar a geração de um relatorio em pdf com BASE na consulta de 06 tabelas mas nao precisa de INNER JOIN.
Vou gerar um PDF com os dados do paciente e abaixo preciso exibir o resultado dos exames que foram cadastrados cada um em uma tabela diferente (TABELA PACIENTE, TABELAEXAME1, TABELAEXAME2, TABELAEXAME3) cada tabela possui o codigo do cliente e os campos dos exames sao diferentes preciso gerar um relatorio de todos os dados do paciente.
ESTOU USANDO O EXEMPLO DO TUTOR. Mas nao sei manipular os repository no metodo ONGENERATE.
O SISTEMA GERA OS DADOS SOMENTE COM OS DADOS DO ULTIMO EXAME. ALGUME PODE ME DAR UMA DICA!
function onGenerate()
{
try
{
TTransaction::open('permission');

$object = $this->form->getData();

$repository = new TRepository('Paciente');
// $complementar = new TRepository('AvaliacaoComplementar');
$equilibrio = new TRepository('AvaliacaoEquilibrio');
// $ombro = new TRepository('AvaliacaoOmbro');
// $well = new TRepository('AvaliacaoWells');
// $minnesota = new TRepository('AvaliacaoMinnesota');
// $avaliacaoClinica = new TRepository('AvaliacaoClinica');
// $hit = new TRepository('AvaliacaoHiit');
// $bdi = new TRepository('AvaliacaoBDI');

$criteria = new TCriteria;
if ($object->codPaciente)
{
$criteria->add(new TFilter('codigoPaciente', '=', "{$object->codPaciente}"));
}

$critEqui = new TCriteria;
$critEqui->add(new TFilter('codPaciente','=',"{$object->codPaciente}"));

$order = isset($param['order']) ? $param['order'] : 'nome';
$criteria ->setProperty('order', $order);

$customers = $repository->load($criteria);
$customers2 = $equilibrio->load($critEqui);

$format = $object->output_type;

if ($customers)
{ //01-02-03--04-05-06-07-08-09
$widths = array(30,60,150,40,90,120,60,60,60);

switch ($format)
{
case 'html':
$tr = new TTableWriterHTML($widths);
break;
case 'pdf':
//alterei o parametro da classe para L paisagem
$tr = new TTableWriterPDF($widths,'L');
break;

}

if (!empty($tr))
{
// create the document styles
$tr->addStyle('title', 'Arial', '10', '', '#d3d3d3', '#407B49');
$tr->addStyle('datap', 'Arial', '8', '', '#000000', '#869FBB');
$tr->addStyle('datai', 'Arial', '8', '', '#000000', '#ffffff');
$tr->addStyle('header', 'Times', '12', '', '#000000', '#B5FFB4');
$tr->addStyle('footer', 'Times', '10', '', '#2B2B2B', '#B5FFB4');

// add a header row
$tr->addRow();
$tr->addCell('Relatório de Pacientes - GPRC', 'center', 'header', 40);

// add titles row
$tr->addRow();
$tr->addCell('Or', 'center', 'title');
$tr->addCell('Id', 'center', 'title');
$tr->addCell('Nome', 'center', 'title');
$tr->addCell('Sexo', 'center', 'title');
$tr->addCell('Idade', 'center', 'title');
$tr->addCell('Email', 'center', 'title');
$tr->addCell('Peso', 'center', 'title');
$tr->addCell('Estatura', 'center', 'title');
$tr->addCell('Telefone', 'center', 'title');

// controls the background filling
$colour= FALSE;
$i=0;
// data rows
foreach ($customers as $customer)
{
$i++;
// $style = $colour ? 'datap' : 'datai';
$style = 'datai';
$tr->addRow();
$tr->addCell($i, 'center', $style);
$tr->addCell($customer->codigoPaciente, 'center', $style);
$tr->addCell($customer->nome, 'center', $style);
$tr->addCell($customer->sexo, 'center', $style);
$tr->addCell($customer->dataNascimento, 'center', $style);
$tr->addCell($customer->email, 'center', $style);
$tr->addCell($customer->peso, 'center', $style);
$tr->addCell($customer->estatura, 'center', $style);
$tr->addCell($customer->telefone, 'center', $style);

$colour = !$colour;
}
}

}

/*
* Implementação do Pdf para Tabela Exame Equilibrio
*/
if ($customers2)
{ //01-02-03--04-05-06-07-08-09
$widths = array(30,60,150,60,80,70,100);

switch ($format)
{
case 'html':
$tr = new TTableWriterHTML($widths);
break;
case 'pdf':
//alterei o parametro da classe para L paisagem
$tr = new TTableWriterPDF($widths,'L');
break;
}

if (!empty($tr))
{
// create the document styles
$tr->addStyle('title', 'Arial', '10', '', '#d3d3d3', '#407B49');
$tr->addStyle('datap', 'Arial', '8', '', '#000000', '#869FBB');
$tr->addStyle('datai', 'Arial', '8', '', '#000000', '#ffffff');
$tr->addStyle('header', 'Times', '12', '', '#000000', '#B5FFB4');
$tr->addStyle('footer', 'Times', '10', '', '#2B2B2B', '#B5FFB4');

// add a header row
$tr->addRow();
$tr->addCell('Exame Equilibrio', 'center', 'header', 40);

// add titles row
$tr->addRow();
$tr->addCell('Or', 'center', 'title');
$tr->addCell('Id', 'center', 'title');
$tr->addCell('Avaliador', 'center', 'title');
$tr->addCell('Media', 'center', 'title');
$tr->addCell('Conclusão', 'center', 'title');
$tr->addCell('Data', 'center', 'title');
$tr->addCell('Parecer', 'center', 'title');

$colour= FALSE;
$i=0;
foreach ($customers2 as $paciente)
{
$i++;
$style = 'datai';
$tr->addRow();
$tr->addCell($i, 'center', $style);
$tr->addCell($paciente->codAvaliacaoEquilibrio, 'center', $style);
$tr->addCell($paciente->codAvaliador, 'center', $style);
$tr->addCell($paciente->media, 'center', $style);
$tr->addCell($paciente->conclusao, 'center', $style);
$tr->addCell($paciente->dataAvaliacao, 'center', $style);
$tr->addCell($paciente->parecer, 'center', $style);

$colour = !$colour;
}
}
}

$tr->addRow();
$tr->addCell(date('Y-m-d h:i:s'), 'center', 'footer', 15);
if (!file_exists("app/output/ficha.{$format}") OR is_writable("app/output/ficha.{$format}"))
{
$tr->save("app/output/ficha.{$format}");
}
else
{
throw new Exception(_t('Permission denied') . ': ' . "app/output/ficha.{$format}");
}

parent::openFile("app/output/ficha.{$format}");




TTransaction::close();

}
catch (Exception $e)
{
new TMessage('error', 'Error ' . $e->getMessage());

TTransaction::rollback();
}

} //fim Generate

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


NR

Se você deseja exibir todas as informações no mesmo arquivo pdf, então instancie somente uma vez a classe TTableWriterPDF.

No código que enviou, você está fazendo isso 2 vezes, uma para cada repositório. Quando você repete esse comando, todas as informações anteriores são perdidas.