Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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: ...
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:
  1. <?php
  2. /**
  3.  * NotasclientesReport Report
  4.  * @author  <UnitSoftware>
  5.  */
  6. class NotasclientesReport extends TPage
  7. {
  8.     protected $form// form
  9.     protected $notebook;
  10.     
  11.     /**
  12.      * Class constructor
  13.      * Creates the page and the registration form
  14.      */
  15.     function __construct()
  16.     {
  17.         parent::__construct();
  18.         
  19.         // creates the form
  20.         $this->form = new TQuickForm('form_NotasclientesModel_report');
  21.         $this->form->class 'tform'// change CSS class
  22.         $this->form = new BootstrapFormWrapper($this->form);
  23.         $this->form->style 'display: table;width:100%'// change style
  24.         
  25.         // define the form title
  26.         $this->form->setFormTitle('NotasclientesModel Report');
  27.         
  28.         // create the form fields
  29.         //$idtbl_Notas = new TEntry('idtbl_Notas');
  30.         $tbl_clientes_tbl_Empresa_idtbl_Empresa = new TDBCombo('tbl_clientes_tbl_Empresa_idtbl_Empresa','conexao','EmpresaModel','idtbl_Empresa','tbl_EmpresaNome');
  31.         //$tbl_clientes_idtbl_Clientes = new TEntry('tbl_clientes_idtbl_Clientes');
  32.         $tbl_NotasTipo = new TCombo('tbl_NotasTipo');
  33.         //$tbl_classificacao_idtbl_classificacao = new TEntry('tbl_classificacao_idtbl_classificacao');
  34.         $tbl_NotasNumero = new TEntry('tbl_NotasNumero');
  35.         $tbl_NotasEmissao = new TDate('tbl_NotasEmissao');
  36.         $tbl_NotasRecebimento = new TDate('tbl_NotasRecebimento');
  37.         //$tbl_NotasValor = new TEntry('tbl_NotasValor');
  38.         //$tbl_NotasValorIcm = new TEntry('tbl_NotasValorIcm');
  39.         //$tbl_NotasPagto = new TEntry('tbl_NotasPagto');
  40.         //$tbl_NotasTotal = new TEntry('tbl_NotasTotal');
  41.         //$tbl_NotasObs = new TEntry('tbl_NotasObs');
  42.         $output_type = new TRadioGroup('output_type');
  43.         //Função
  44.         $tbl_NotasTipo->addItems(array('Entrada'=>'Entrada''Saida'=>'Saida'));
  45.         
  46.         
  47.         
  48.         // add the fields
  49.         //$this->form->addQuickField('Idtbl Notas', $idtbl_Notas,  '50%' );
  50.         $this->form->addQuickField('Empresa :'$tbl_clientes_tbl_Empresa_idtbl_Empresa,  '50%' );
  51.         //$this->form->addQuickField('Clientes :', $tbl_clientes_idtbl_Clientes,  '50%' );
  52.         $this->form->addQuickField('Tipo :'$tbl_NotasTipo,  '50%' );
  53.         //$this->form->addQuickField('Classificacao Fiscal :', $tbl_classificacao_idtbl_classificacao,  '50%' );
  54.         $this->form->addQuickField('Número :'$tbl_NotasNumero,  '50%' );
  55.         $this->form->addQuickField('Emissão :'$tbl_NotasEmissao,  '50%' );
  56.         $this->form->addQuickField('Recebimento :'$tbl_NotasRecebimento,  '50%' );
  57.         //$this->form->addQuickField('Valor :', $tbl_NotasValor,  '100%' );
  58.         //$this->form->addQuickField('Icms :', $tbl_NotasValorIcm,  '50%' );
  59.         //$this->form->addQuickField('Pagamento :', $tbl_NotasPagto,  '100%' );
  60.         //$this->form->addQuickField('Total :', $tbl_NotasTotal,  '100%' );
  61.         //$this->form->addQuickField('Observação :', $tbl_NotasObs,  '100%' );
  62.         $this->form->addQuickField('Saída :'$output_type,  '100%' , new TRequiredValidator);
  63.         
  64.         $output_type->addItems(array('html'=>'HTML''pdf'=>'PDF''rtf'=>'RTF'));;
  65.         $output_type->setValue('pdf');
  66.         $output_type->setLayout('horizontal');
  67.         
  68.         // add the action button
  69.         $btn $this->form->addQuickAction(_t('Generate'), new TAction(array($this'onGenerate')), 'fa:cog');
  70.         $btn->class 'btn btn-sm btn-primary';
  71.         
  72.         // vertical box container
  73.         $container = new TVBox;
  74.         $container->style 'width: 100%';
  75.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  76.         $container->add(TPanelGroup::pack('Relatório de Notas Fiscais de Cliente por Empresa'$this->form));
  77.         
  78.         parent::add($container);
  79.     }
  80.     
  81.     /**
  82.      * Generate the report
  83.      */
  84.     function onGenerate()
  85.     {
  86.         try
  87.         {
  88.             // open a transaction with database 'conexao'
  89.             TTransaction::open('conexao');
  90.             
  91.             // get the form data into an active record
  92.             $formdata $this->form->getData();
  93.             
  94.             $repository = new TRepository('NotasclientesModel');
  95.             $criteria   = new TCriteria;
  96.             
  97.             /*if ($formdata->idtbl_Notas)
  98.             {
  99.                 $criteria->add(new TFilter('idtbl_Notas', 'like', "%{$formdata->idtbl_Notas}%"));
  100.             }*/
  101.             if ($formdata->tbl_clientes_tbl_Empresa_idtbl_Empresa)
  102.             {
  103.                 $criteria->add(new TFilter('tbl_clientes_tbl_Empresa_idtbl_Empresa''like'"%{$formdata->tbl_clientes_tbl_Empresa_idtbl_Empresa}%"));
  104.             }
  105.             /*if ($formdata->tbl_clientes_idtbl_Clientes)
  106.             {
  107.                 $criteria->add(new TFilter('tbl_clientes_idtbl_Clientes', 'like', "%{$formdata->tbl_clientes_idtbl_Clientes}%"));
  108.             }*/
  109.             if ($formdata->tbl_NotasTipo)
  110.             {
  111.                 $criteria->add(new TFilter('tbl_NotasTipo''like'"%{$formdata->tbl_NotasTipo}%"));
  112.             }
  113.             /*if ($formdata->tbl_classificacao_idtbl_classificacao)
  114.             {
  115.                 $criteria->add(new TFilter('tbl_classificacao_idtbl_classificacao', 'like', "%{$formdata->tbl_classificacao_idtbl_classificacao}%"));
  116.             }*/
  117.             if ($formdata->tbl_NotasNumero)
  118.             {
  119.                 $criteria->add(new TFilter('tbl_NotasNumero''like'"%{$formdata->tbl_NotasNumero}%"));
  120.             }
  121.             if ($formdata->tbl_NotasEmissao)
  122.             {
  123.                 $criteria->add(new TFilter('tbl_NotasEmissao''like'"%{$formdata->tbl_NotasEmissao}%"));
  124.             }
  125.             if ($formdata->tbl_NotasRecebimento)
  126.             {
  127.                 $criteria->add(new TFilter('tbl_NotasRecebimento''like'"%{$formdata->tbl_NotasRecebimento}%"));
  128.             }
  129.             /*if ($formdata->tbl_NotasValor)
  130.             {
  131.                 $criteria->add(new TFilter('tbl_NotasValor', 'like', "%{$formdata->tbl_NotasValor}%"));
  132.             }*/
  133.             /*if ($formdata->tbl_NotasValorIcm)
  134.             {
  135.                 $criteria->add(new TFilter('tbl_NotasValorIcm', 'like', "%{$formdata->tbl_NotasValorIcm}%"));
  136.             }*/
  137.             /*if ($formdata->tbl_NotasPagto)
  138.             {
  139.                 $criteria->add(new TFilter('tbl_NotasPagto', 'like', "%{$formdata->tbl_NotasPagto}%"));
  140.             }*/
  141.             /*if ($formdata->tbl_NotasTotal)
  142.             {
  143.                 $criteria->add(new TFilter('tbl_NotasTotal', 'like', "%{$formdata->tbl_NotasTotal}%"));
  144.             }*/
  145.             /*if ($formdata->tbl_NotasObs)
  146.             {
  147.                 $criteria->add(new TFilter('tbl_NotasObs', 'like', "%{$formdata->tbl_NotasObs}%"));
  148.             }*/
  149.            
  150.             $objects $repository->load($criteriaFALSE);
  151.             $format  $formdata->output_type;
  152.             
  153.             if ($objects)
  154.             {
  155.                 $widths = array(50,50,50,100,50,100,50,50,100,50,100,100,100);
  156.                 
  157.                 switch ($format)
  158.                 {
  159.                     case 'html':
  160.                         $tr = new TTableWriterHTML($widths);
  161.                         break;
  162.                     case 'pdf':
  163.                         $tr = new TTableWriterPDF($widths);
  164.                         break;
  165.                     case 'rtf':
  166.                         if (!class_exists('PHPRtfLite_Autoloader'))
  167.                         {
  168.                             PHPRtfLite::registerAutoloader();
  169.                         }
  170.                         $tr = new TTableWriterRTF($widths);
  171.                         break;
  172.                 }
  173.                 
  174.                 // create the document styles
  175.                 $tr->addStyle('title''Arial''10''B',   '#ffffff''#EA9C98');
  176.                 $tr->addStyle('datap''Arial''10''',    '#000000''#EEEEEE');
  177.                 $tr->addStyle('datai''Arial''10''',    '#000000''#ffffff');
  178.                 $tr->addStyle('header''Arial''16''',   '#ffffff''#904F49');
  179.                 $tr->addStyle('footer''Times''10''I',  '#000000''#F2BEBC');
  180.                 
  181.                 // add a header row
  182.                 $tr->addRow();
  183.                 $tr->addCell('Apuração das Notas ''center''header'13);
  184.                 
  185.                 //$tr->addRow();
  186.                 //$tr->addCell('Empresa :','cnter','header');
  187.                 //$tr->addCell('clientes_model->tbl_ClientesNome');
  188.                 
  189.                 // add titles row
  190.                 $tr->addRow();
  191.                 $tr->addCell('Número :''right''title');
  192.                 $tr->addCell('Empresa :''right''title');
  193.                 $tr->addCell('Clientes :''right''title');
  194.                 $tr->addCell('Tipo :''left''title');
  195.                 $tr->addCell('Classificacao Fiscal :''right''title');
  196.                 $tr->addCell('Número :''center''title');
  197.                 $tr->addCell('Emissão :''center''title');
  198.                 $tr->addCell('Recebimento :''left''title');
  199.                 $tr->addCell('Valor :''left''title');
  200.                 $tr->addCell('Icms :''right''title');
  201.                 $tr->addCell('Pagamento :''left''title');
  202.                 $tr->addCell('Total :''left''title');
  203.                 $tr->addCell('Observação :''left''title');
  204.                 
  205.                 // controls the background filling
  206.                 $colourFALSE;
  207.                 $total 0;
  208.                 // data rows
  209.                 foreach ($objects as $object)
  210.                 {
  211.                     $style $colour 'datap' 'datai';
  212.                     $tr->addRow();
  213.                     $tr->addCell($object->idtbl_Notas'center'$style);
  214.                     $tr->addCell($object->tbl_clientes_tbl_Empresa_idtbl_Empresa'center'$style);
  215.                     $tr->addCell($object->tbl_clientes_idtbl_Clientes'center'$style);
  216.                     $tr->addCell($object->tbl_NotasTipo'center'$style);
  217.                     $tr->addCell($object->tbl_classificacao_idtbl_classificacao'center'$style);
  218.                     $tr->addCell($object->tbl_NotasNumero'center'$style);
  219.                     $tr->addCell($object->tbl_NotasEmissao'center'$style);
  220.                     $tr->addCell($object->tbl_NotasRecebimento'center'$style);
  221.                     $tr->addCell($object->tbl_NotasValor'center'$style);
  222.                     $tr->addCell($object->tbl_NotasValorIcm'center'$style);
  223.                     $tr->addCell($object->tbl_NotasPagto'center'$style);
  224.                     $tr->addCell($object->tbl_NotasTotal'center'$style);
  225.                     //$tr->addCell($object->tbl_NotasObs, 'center', $style);
  226.                     
  227.                     $total += $object->tbl_NotasTotal;
  228.                     
  229.                     
  230.                     $colour = !$colour;
  231.                 }
  232.                 
  233.                 $tr->addRow();
  234.                 $tr->addCell('Total Geral R$:''center''footer',5);
  235.                 $tr->addCell(number_format($total,2,',','.'),'center'$style7);      
  236.                 
  237.                 
  238.                 
  239.                 // footer row
  240.                 $tr->addRow();
  241.                 $tr->addCell(date('d/m/Y h:i:s'), 'center''footer'13);
  242.                 // stores the file
  243.                 if (!file_exists("app/output/NotasclientesModel.{$format}") OR is_writable("app/output/NotasclientesModel.{$format}"))
  244.                 {
  245.                     $tr->save("app/output/NotasclientesModel.{$format}");
  246.                 }
  247.                 else
  248.                 {
  249.                     throw new Exception(_t('Permission denied') . ': ' "app/output/NotasclientesModel.{$format}");
  250.                 }
  251.                 
  252.                 // open the report file
  253.                 parent::openFile("app/output/NotasclientesModel.{$format}");
  254.                 
  255.                 // shows the success message
  256.                 new TMessage('info''Relatório Gerado.');
  257.             }
  258.             else
  259.             {
  260.                 new TMessage('error''Não Existe nenhum relatório para esta Empresa');
  261.             }
  262.     
  263.             // fill the form with the active record data
  264.             $this->form->setData($formdata);
  265.             
  266.             // close the transaction
  267.             TTransaction::close();
  268.         }
  269.         catch (Exception $e// in case of exception
  270.         {
  271.             // shows the exception error message
  272.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  273.             
  274.             // undo all pending operations
  275.             TTransaction::rollback();
  276.         }
  277.     }
  278. }
  279. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (4)


HL

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.
FC
AM

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
AM

Obrigado a todos, consegui resolver, um abraço.