AM
Ajuda perante como trocar o id do fornecedor pelo nome
Boa Noite amigos, estou apanhando para trocar no relatório o id do cliente pelo nome , tenho uma tabela empresa onde cada empresa tem os seus fornecedores, tenho uma tabela notas, meu relatório esta funcionando porém não quero puxar o id mas o nome da empresa , alguém pode me ajudar, segue abaixo o código:
- <?php
- /**
- * NotasclientesReport Report
- * @author <UnitSoftware>
- */
- class NotasclientesReport extends TPage
- {
- protected $form; // form
- protected $notebook;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TQuickForm('form_NotasclientesModel_report');
- $this->form->class = 'tform'; // change CSS class
- $this->form = new BootstrapFormWrapper($this->form);
- $this->form->style = 'display: table;width:100%'; // change style
- // define the form title
- $this->form->setFormTitle('NotasclientesModel Report');
- // create the form fields
- //$idtbl_Notas = new TEntry('idtbl_Notas');
- $tbl_clientes_tbl_Empresa_idtbl_Empresa = new TDBCombo('tbl_clientes_tbl_Empresa_idtbl_Empresa','conexao','EmpresaModel','idtbl_Empresa','tbl_EmpresaNome');
- //$tbl_clientes_idtbl_Clientes = new TEntry('tbl_clientes_idtbl_Clientes');
- $tbl_NotasTipo = new TCombo('tbl_NotasTipo');
- //$tbl_classificacao_idtbl_classificacao = new TEntry('tbl_classificacao_idtbl_classificacao');
- $tbl_NotasNumero = new TEntry('tbl_NotasNumero');
- $tbl_NotasEmissao = new TDate('tbl_NotasEmissao');
- $tbl_NotasRecebimento = new TDate('tbl_NotasRecebimento');
- //$tbl_NotasValor = new TEntry('tbl_NotasValor');
- //$tbl_NotasValorIcm = new TEntry('tbl_NotasValorIcm');
- //$tbl_NotasPagto = new TEntry('tbl_NotasPagto');
- //$tbl_NotasTotal = new TEntry('tbl_NotasTotal');
- //$tbl_NotasObs = new TEntry('tbl_NotasObs');
- $output_type = new TRadioGroup('output_type');
- //Função
- $tbl_NotasTipo->addItems(array('Entrada'=>'Entrada', 'Saida'=>'Saida'));
- // add the fields
- //$this->form->addQuickField('Idtbl Notas', $idtbl_Notas, '50%' );
- $this->form->addQuickField('Empresa :', $tbl_clientes_tbl_Empresa_idtbl_Empresa, '50%' );
- //$this->form->addQuickField('Clientes :', $tbl_clientes_idtbl_Clientes, '50%' );
- $this->form->addQuickField('Tipo :', $tbl_NotasTipo, '50%' );
- //$this->form->addQuickField('Classificacao Fiscal :', $tbl_classificacao_idtbl_classificacao, '50%' );
- $this->form->addQuickField('Número :', $tbl_NotasNumero, '50%' );
- $this->form->addQuickField('Emissão :', $tbl_NotasEmissao, '50%' );
- $this->form->addQuickField('Recebimento :', $tbl_NotasRecebimento, '50%' );
- //$this->form->addQuickField('Valor :', $tbl_NotasValor, '100%' );
- //$this->form->addQuickField('Icms :', $tbl_NotasValorIcm, '50%' );
- //$this->form->addQuickField('Pagamento :', $tbl_NotasPagto, '100%' );
- //$this->form->addQuickField('Total :', $tbl_NotasTotal, '100%' );
- //$this->form->addQuickField('Observação :', $tbl_NotasObs, '100%' );
- $this->form->addQuickField('Saída :', $output_type, '100%' , new TRequiredValidator);
- $output_type->addItems(array('html'=>'HTML', 'pdf'=>'PDF', 'rtf'=>'RTF'));;
- $output_type->setValue('pdf');
- $output_type->setLayout('horizontal');
- // add the action button
- $btn = $this->form->addQuickAction(_t('Generate'), new TAction(array($this, 'onGenerate')), 'fa:cog');
- $btn->class = 'btn btn-sm btn-primary';
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 100%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add(TPanelGroup::pack('Relatório de Notas Fiscais de Cliente por Empresa', $this->form));
- parent::add($container);
- }
- /**
- * Generate the report
- */
- function onGenerate()
- {
- try
- {
- // open a transaction with database 'conexao'
- TTransaction::open('conexao');
- // get the form data into an active record
- $formdata = $this->form->getData();
- $repository = new TRepository('NotasclientesModel');
- $criteria = new TCriteria;
- /*if ($formdata->idtbl_Notas)
- {
- $criteria->add(new TFilter('idtbl_Notas', 'like', "%{$formdata->idtbl_Notas}%"));
- }*/
- if ($formdata->tbl_clientes_tbl_Empresa_idtbl_Empresa)
- {
- $criteria->add(new TFilter('tbl_clientes_tbl_Empresa_idtbl_Empresa', 'like', "%{$formdata->tbl_clientes_tbl_Empresa_idtbl_Empresa}%"));
- }
- /*if ($formdata->tbl_clientes_idtbl_Clientes)
- {
- $criteria->add(new TFilter('tbl_clientes_idtbl_Clientes', 'like', "%{$formdata->tbl_clientes_idtbl_Clientes}%"));
- }*/
- if ($formdata->tbl_NotasTipo)
- {
- $criteria->add(new TFilter('tbl_NotasTipo', 'like', "%{$formdata->tbl_NotasTipo}%"));
- }
- /*if ($formdata->tbl_classificacao_idtbl_classificacao)
- {
- $criteria->add(new TFilter('tbl_classificacao_idtbl_classificacao', 'like', "%{$formdata->tbl_classificacao_idtbl_classificacao}%"));
- }*/
- if ($formdata->tbl_NotasNumero)
- {
- $criteria->add(new TFilter('tbl_NotasNumero', 'like', "%{$formdata->tbl_NotasNumero}%"));
- }
- if ($formdata->tbl_NotasEmissao)
- {
- $criteria->add(new TFilter('tbl_NotasEmissao', 'like', "%{$formdata->tbl_NotasEmissao}%"));
- }
- if ($formdata->tbl_NotasRecebimento)
- {
- $criteria->add(new TFilter('tbl_NotasRecebimento', 'like', "%{$formdata->tbl_NotasRecebimento}%"));
- }
- /*if ($formdata->tbl_NotasValor)
- {
- $criteria->add(new TFilter('tbl_NotasValor', 'like', "%{$formdata->tbl_NotasValor}%"));
- }*/
- /*if ($formdata->tbl_NotasValorIcm)
- {
- $criteria->add(new TFilter('tbl_NotasValorIcm', 'like', "%{$formdata->tbl_NotasValorIcm}%"));
- }*/
- /*if ($formdata->tbl_NotasPagto)
- {
- $criteria->add(new TFilter('tbl_NotasPagto', 'like', "%{$formdata->tbl_NotasPagto}%"));
- }*/
- /*if ($formdata->tbl_NotasTotal)
- {
- $criteria->add(new TFilter('tbl_NotasTotal', 'like', "%{$formdata->tbl_NotasTotal}%"));
- }*/
- /*if ($formdata->tbl_NotasObs)
- {
- $criteria->add(new TFilter('tbl_NotasObs', 'like', "%{$formdata->tbl_NotasObs}%"));
- }*/
- $objects = $repository->load($criteria, FALSE);
- $format = $formdata->output_type;
- if ($objects)
- {
- $widths = array(50,50,50,100,50,100,50,50,100,50,100,100,100);
- switch ($format)
- {
- case 'html':
- $tr = new TTableWriterHTML($widths);
- break;
- case 'pdf':
- $tr = new TTableWriterPDF($widths);
- break;
- case 'rtf':
- if (!class_exists('PHPRtfLite_Autoloader'))
- {
- PHPRtfLite::registerAutoloader();
- }
- $tr = new TTableWriterRTF($widths);
- break;
- }
- // create the document styles
- $tr->addStyle('title', 'Arial', '10', 'B', '#ffffff', '#EA9C98');
- $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#EEEEEE');
- $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
- $tr->addStyle('header', 'Arial', '16', '', '#ffffff', '#904F49');
- $tr->addStyle('footer', 'Times', '10', 'I', '#000000', '#F2BEBC');
- // add a header row
- $tr->addRow();
- $tr->addCell('Apuração das Notas ', 'center', 'header', 13);
- //$tr->addRow();
- //$tr->addCell('Empresa :','cnter','header');
- //$tr->addCell('clientes_model->tbl_ClientesNome');
- // add titles row
- $tr->addRow();
- $tr->addCell('Número :', 'right', 'title');
- $tr->addCell('Empresa :', 'right', 'title');
- $tr->addCell('Clientes :', 'right', 'title');
- $tr->addCell('Tipo :', 'left', 'title');
- $tr->addCell('Classificacao Fiscal :', 'right', 'title');
- $tr->addCell('Número :', 'center', 'title');
- $tr->addCell('Emissão :', 'center', 'title');
- $tr->addCell('Recebimento :', 'left', 'title');
- $tr->addCell('Valor :', 'left', 'title');
- $tr->addCell('Icms :', 'right', 'title');
- $tr->addCell('Pagamento :', 'left', 'title');
- $tr->addCell('Total :', 'left', 'title');
- $tr->addCell('Observação :', 'left', 'title');
- // controls the background filling
- $colour= FALSE;
- $total = 0;
- // data rows
- foreach ($objects as $object)
- {
- $style = $colour ? 'datap' : 'datai';
- $tr->addRow();
- $tr->addCell($object->idtbl_Notas, 'center', $style);
- $tr->addCell($object->tbl_clientes_tbl_Empresa_idtbl_Empresa, 'center', $style);
- $tr->addCell($object->tbl_clientes_idtbl_Clientes, 'center', $style);
- $tr->addCell($object->tbl_NotasTipo, 'center', $style);
- $tr->addCell($object->tbl_classificacao_idtbl_classificacao, 'center', $style);
- $tr->addCell($object->tbl_NotasNumero, 'center', $style);
- $tr->addCell($object->tbl_NotasEmissao, 'center', $style);
- $tr->addCell($object->tbl_NotasRecebimento, 'center', $style);
- $tr->addCell($object->tbl_NotasValor, 'center', $style);
- $tr->addCell($object->tbl_NotasValorIcm, 'center', $style);
- $tr->addCell($object->tbl_NotasPagto, 'center', $style);
- $tr->addCell($object->tbl_NotasTotal, 'center', $style);
- //$tr->addCell($object->tbl_NotasObs, 'center', $style);
- $total += $object->tbl_NotasTotal;
- $colour = !$colour;
- }
- $tr->addRow();
- $tr->addCell('Total Geral R$:', 'center', 'footer',5);
- $tr->addCell(number_format($total,2,',','.'),'center', $style, 7);
- // footer row
- $tr->addRow();
- $tr->addCell(date('d/m/Y h:i:s'), 'center', 'footer', 13);
- // stores the file
- if (!file_exists("app/output/NotasclientesModel.{$format}") OR is_writable("app/output/NotasclientesModel.{$format}"))
- {
- $tr->save("app/output/NotasclientesModel.{$format}");
- }
- else
- {
- throw new Exception(_t('Permission denied') . ': ' . "app/output/NotasclientesModel.{$format}");
- }
- // open the report file
- parent::openFile("app/output/NotasclientesModel.{$format}");
- // shows the success message
- new TMessage('info', 'Relatório Gerado.');
- }
- else
- {
- new TMessage('error', 'Não Existe nenhum relatório para esta Empresa');
- }
- // fill the form with the active record data
- $this->form->setData($formdata);
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
- ?>
Alexsander, você pode dar uma olhada neste exemplo (www.adianti.com.br/framework_files/tutor/index.php?class=AssociationView) do tutor, que deve atender as suas necessidades
Ou
outra alternativa é a criação de uma View com as associações necessárias no seu banco de dados.
www.adianti.com.br/forum/pt/view_879?relatorios-com-queries-complexa
Boa tarde, desculpe a demora, corrigir e fiz pelo método de associação , ele gera o relatório , porém me dá os seguintes erros :
Warning: Use of undefined constant tbl_EmpresaNome - assumed 'tbl_EmpresaNome' (this will throw an Error in a future version of PHP) in C:xampphtdocsProjetosPHPUnitsoftwareContabilidadeappcontrolsistemarelatoriosClientesClientesReport.class.php on line 173
Warning: Use of undefined constant tbl_CidadesNome - assumed 'tbl_CidadesNome' (this will throw an Error in a future version of PHP) in C:xampphtdocsProjetosPHPUnitsoftwareContabilidadeappcontrolsistemarelatoriosClientesClientesReport.class.php on line 213
Warning: Use of undefined constant tbl_EstadosUf - assumed 'tbl_EstadosUf' (this will throw an Error in a future version of PHP) in C:xampphtdocsProjetosPHPUnitsoftwareContabilidadeappcontrolsistemarelatoriosClientesClientesReport.class.php on line 214
Obrigado a todos, consegui resolver, um abraço.