Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Caros amigos, saudações.
Após algumas pesquisas e ajuda dos amigos, consegui resolver um probleminha de Relatório em Codeigniter, usando o FPDF para imprimir.
Estou com um problema de Título no Relatório. Gostaria de passar para o Relatório a DataInicial e DataFinal no título, não estou conseguindo.
Abaixo os Código.
controller está assim:
<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Relatorios extends CI_Controller{
public function __construct() {
parent::__construct();
if ((!session_id()) || (!$this->session->userdata('logado'))) {
redirect('seular/login');
}
$this->load->model('Relatorios_model', '', true);
$this->load->model('Usuarios_model', '', true);
$this->load->model('Seular_model', '', true);
$this->load->library('myfpdf');
$this->data['menuRelatorios'] = 'relatorios';
}
public function index(){
header('Location: ./');
}
//Início de Relatório para Cliente
public function clientes(){
if (!$this->permission->checkPermission($this->session->userdata('permissao'), 'rCliente')) {
$this->session->set_flashdata('error', 'Você não tem permissão para gerar relatórios de clientes.');
redirect(base_url());
}
$this->data['view'] = 'relatorios/rel_clientes';
$this->load->view('tema/topo', $this->data);
}
//Imprime os Clientes por Data escolhida
public function clientesCustom(){
if (!$this->permission->checkPermission($this->session->userdata('permissao'), 'rCliente')) {
$this->session->set_flashdata('error', 'Você não tem permissão para gerar relatórios de clientes.');
redirect(base_url());
}
$dataInicial = $this->input->get('dataInicial');
$dataFinal = $this->input->get('dataFinal');
$data = $this->Relatorios_model->clientesCustom($dataInicial, $dataFinal);
$this->load->view('relatorios/imprimir/printClientes', ['data'=>$data]);
}
}
a model está assim:
<?php
class Relatorios_model extends CI_Model {
function __construct() {
parent::__construct();
$this->load->database();
}
//Clientes - faz a pesquisa por data corretamente
public function clientesCustom($dataInicial = null,$dataFinal = null){
if($dataInicial == null || $dataFinal == null){
$dataInicial = date('Y-m-d');
$dataFinal = date('Y-m-d');
}
$query = "SELECT * FROM clientes WHERE dataCadastro BETWEEN ? AND ? ORDER BY nomeCliente ASC";
$this->db->select('*');
$this->db->from('clientes');
$data = $this->db->query($query, array($dataInicial,$dataFinal));
return $data;
}
}
para imprimir está assim:
<?php
class PDF extends FPDF{
// Page header
function Header(){
$corLin = $this->SetFillColor(144, 144, 144);
$this->Image('assets/img/logo.png',5,5,20);
$this->SetFont('Arial', '', 9);
$this->SetTextColor(35,35,35);
$this->Cell(198, 5, date('d/m/Y').' - '.date('H:i:s'), 0,0,'R');
$this->Ln();
$this->SetFont('Arial','B',18);
$this->SetTextColor(10,10,88);
$this->Cell(190,5,utf8_decode('RELATÓRIO DE CLIENTES'),0,0,'C');
$this->Ln();
$this->SetFont('Arial','',12);
$this->SetTextColor(35,35,35);
$this->Cell(190,5,utf8_decode('Ordem Alfabética'),0,0,'C');
$this->Ln(10);
$this->Cell(13,5,'',0,0);
$this->Cell(175,1,$corLin,0,0,'',1); //Muda a cor da linha
$this->Ln(5);
}
function conteudo($data){
if($data->result() == NULL){
$this->Ln(15);
$this->SetFont('Arial','B',18);
$this->SetTextColor(0,0,0);
$this->Cell(21,5,'',0,0);
$this->Cell(21,5,utf8_decode('Atenção:'),0,0,'L');
$this->Ln(12);
$this->SetFont('Arial','B',16);
$this->SetTextColor(201,7,7);
$this->Cell(21,5,'',0,0);
$this->Cell(21,5,utf8_decode('Não foi informado nenhuma data para pesquisa.'),0,0,'L');
$this->SetTextColor(0,0,0);
$this->Ln(10);
} else {
$corLin = $this->SetFillColor(33, 160, 33);
foreach($data->result() as $cl){
//Imprime todos os clientes cadastrados
$this->Ln();
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(30,10,'Data de Cadastro:',0,0,'L');
$this->SetFont('Arial','B',10);
$this->Cell(30,10, date('d/m/Y', strtotime($cl->dataCadastro)),0,0,'L');
$this->Ln(9);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(20,10,utf8_decode('Código:'),0,0,'L');
$this->Cell(25,10,utf8_decode('Razão Social:'),0,0,'L');
$this->Ln(4.5);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','B',10);
$this->Cell(20,10,str_pad($cl->idClientes,'5','0', STR_PAD_LEFT),0,0,'L');
$this->Cell(160,10,utf8_decode($cl->nomeCliente),0,0,'L');
$this->Ln(7);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(45,10,utf8_decode('Documento:'),0,0,'L');
$this->Cell(40,10,utf8_decode('Telefone:'),0,0,'L');
$this->Cell(93,10,utf8_decode('Celular:'),0,0,'L');
$this->Ln(4.5);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','B',10);
$this->Cell(45,10,$cl->documento,0,0,'L');
$this->Cell(40,10,$cl->telefone,0,0,'L');
$this->Cell(93,10,$cl->celular,0,0,'L');
$this->Ln(7);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(100,10,utf8_decode('Endereço:'),0,0,'L');
$this->Cell(19,10,utf8_decode('Número:'),0,0,'L');
$this->Cell(61,10,utf8_decode('Complemento:'),0,0,'L');
$this->Ln(4.5);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','B',10);
$this->Cell(100,10,utf8_decode($cl->endereco),0,0,'L');
$this->Cell(19,10,$cl->numero,0,0,'L');
$this->Cell(61,10,utf8_decode($cl->compl),0,0,'L');
$this->Ln(7);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(65,10,utf8_decode('Bairro:'),0,0,'L');
$this->Cell(75,10,utf8_decode('Cidade:'),0,0,'L');
$this->Cell(15,10,utf8_decode('UF:'),0,0,'L');
$this->Cell(10,10,utf8_decode('CEP:'),0,0,'L');
$this->Ln(4.5);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','B',10);
$this->Cell(65,10,utf8_decode($cl->bairro),0,0,'L');
$this->Cell(75,10,utf8_decode($cl->cidade),0,0,'L');
$this->Cell(15,10,$cl->estado,0,0,'L');
$this->Cell(10,10,$cl->cep,0,0,'L');
$this->Ln(7);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(33,10,utf8_decode('E-mail:'),0,0,'L');
$this->Ln(4.5);
$this->Cell(13,5,'',0,0);
$this->SetFont('Arial','B',10);
$this->Cell(100,10,utf8_decode($cl->email),0,0,'L');
$this->Ln(15);
$this->Cell(13,5,'',0,0);
$this->Cell(175,1,$corLin,0,0,'',1); //Muda a cor da linha
$this->Ln(3);
}//Fim Foreach
}//Fim IF
}
// Page footer
function Footer(){
$this->SetY(-15);
$this->SetFont('Arial','',9);
$this->Cell(0,10,utf8_decode('F5 | Imobiliária'),0,0,'L');
$this->SetFont('Arial','B',10);
$this->Cell(0,10,$this->PageNo(),0,0,'R');
}
}
// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->SetTitle(utf8_decode('Relatório de Clientes'));
$pdf->AddPage('P','A4',0);
$pdf->SetFont('Times','',12);
$pdf->conteudo($data);
$pdf->Output('RelacaoCliente.pdf',"I");
?>
Grato,
RenatoCarregando comentários...