Newerton, on 06 March 2012 - 04:22 PM, said:
Amigo é o seguinte, conseguir gerar o arquivo porém gostaria de implementá-lo assim:
No meu
admin tá assim
<div class="example_title">
<img src="<?php echo Yii::app()->request->baseUrl; ?>/images/atualizar.png" alt="logo" />
<?php echo "Atualizações das CTPS's"; ?>
</div>
<?php $this->renderPartial('_filter', array('drtFilter' => $drtFilter)); ?>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'atualizar-grid',
'dataProvider' => $dataProvider,
//'filter' => $model,
'pager' => array('cssFile' => Yii::app()->baseUrl . '/css/gridViewStyle/gridView.css'),
'cssFile' => Yii::app()->baseUrl . '/css/gridViewStyle/gridView.css',
'htmlOptions' => array('class' => 'grid-view rounded'),
'rowCssClass' => array('odd', 'even', 'redodd', 'redeven'),
'rowCssClassExpression' => '$this->dataProvider->data[$row]->statusAtualizacao==atualizar::DEVOLVIDO?$this->rowCssClass[$row%2+2]:$this->rowCssClass[$row%2]',
'columns' => array(
...............
),
));
?>
Onde solicito ao usuário o
drt do funcionário para filtrar a GridView, até aí tudo bem. O que queria era ao lado do botão Filtrar colocar um
imprimir também. Só que não estou conseguindo.
O
_filter tá assim:
<div class="form">
<?php echo CHtml::beginForm(); ?>
<fieldset>
<div class="row">
<?php echo CHtml::label('Pesquisar o DRT', 'drt'); ?>
<?php echo CHtml::textField('drt', $drtFilter, array("style" => "background:gold; color:blue; border-bottom:1px solid blue; border-top:1px solid blue; border-left:1px solid blue; border-right:1px solid blue")); ?>
<?php echo CHtml::submitButton('Filtrar'); ?>
<?php echo CHtml::submitButton('Imprimir'); ?> <!-- Gostaria de colocar botão para funcionar -->
</div>
</fieldset>
<?php echo CHtml::endForm(); ?>
</div><!-- form -->
No
Controller criei a função
print e está assim:
public function actionPrint() {
$dir = dirname(__FILE__) . '/pdf/';
/* Nome do arquivo */
$file = time() . '.pdf';
/* Importando a classe */
Yii::import('application.extensions.mpdf.mpdf');
$mpdf = new mpdf();
if ($_POST["drt"] == '') {
$sql = "SELECT col.drt, col.nome, att.convocacao, att.recebimento, att.atualizacao, att.devolucao, att.observacao
FROM colab col
INNER JOIN atualizar att ON att.colaborador = col.idcolab
ORDER BY col.nome ASC";
} else {
$sql = "SELECT col.drt, col.nome, att.convocacao, att.recebimento, att.atualizacao, att.devolucao, att.observacao
FROM colab col
INNER JOIN atualizar att ON att.colaborador = col.idcolab
WHERE col.drt = '{$_POST["drt"]}'
ORDER BY col.nome ASC ";
}
$conn = Yii::app()->db->createCommand($sql)->queryAll();
$html .= '<html>';
$html .= '<head>';
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$html .= '<meta http-equiv="Content-Language" content="pt-br, pt">';
$html .= '<title>Impressão de Atualizações de CTPS</title>';
$html .= '</head>';
$html .= '<body>';
$html .= '<table border="0" width="650">';
$html .= '<tbody>';
$html .= '<tr>';
$html .= '<td>';
$html .= '<p style="text-align: center;"><img src="' . Yii::app()->baseUrl . '/images/logo.png" border="0" /></p>';
$html .= '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td style="text-align: center;"><span style="color: #000080;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;"><b>SETOR</b></span></span></span></td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td style="text-align: center;"><span style="color: #000080;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;"><b>ATUALIZAÇÕES DA CTPS</b></span></span></span></td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td></td>';
$html .= '</tr>';
$html .= '</tbody>';
$html .= '</table>';
$html .= '<p>';
$html .= '<table border="1" width="650" frame="border" rules="all">';
$html .= '<tbody>';
$html .= '<tr style="background-color: #d0cdd4;">';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;"><b>DRT - Nome</b></span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;"><b>Convocação</b></span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;"><b>Recebimento</b></span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;"><b>Atualização</b></span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;"><b>Devolução</b></span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;"><b>Observações</b></span></td>';
$html .= '</tr>';
foreach ($conn as $row) {
$html .= '<tr>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;">' . $row['drt'] . " - " . $row['nome'] . '</span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;">' . $row['convocacao'] . '</span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;">' . $row['recebimento'] . '</span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;">' . $row['atualizacao'] . '</span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;">' . $row['devolucao'] . '</span></td>';
$html .= '<td><span style="font-family: verdana,geneva; font-size: 12;">' . $row['observacao'] . '</span></td>';
$html .= '</tr>';
$html .= '</tbody>';
}
$html .= '</table>';
$html .= '</p>';
$html .= '<script type="text/javascript">
print();
</script>';
$html .= '</body>';
$html .= '</html>';
echo $html;
/* $mpdf->WriteHTML($html);
$mpdf->Output($file,'D'); */
}
Em anexo como está hoje a página, percebam que o
Filter tá OK e agora só falta colocar o
Imprimir pra funcionar. O que fiz de errado ou esqueci???