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...
Estou com o seguinte problema para Gerar um Relatório.
O problema é o seguinte:
--> quando o Sistema gera o Relatório traz todas as informações corretas, com exceção dos itens que Cada Cliente comprou, por exemplo:
-
o Cliente Fulano comprou 3 itens..: caderno / lápis / caneta
-
o Cliente Beltrano comprou 4 itens: borracha / régua / caneta / caderno
-
o Cliente Ciclano comprou 2 itens.: apontador / caixa de lápis de cor
Quando o Sistema gera o Relatório, traz todas as Informações de Cada Cliente com os seus dados corretamente, mas quando deve mostrar os ITENS que cada Cliente comprou, traz as informações tudo errada.
O que o sistema mostra são os ITENS que o Cliente cadastrou em seu sistema para venda e não o que os Clientes compraram.
Observação: a Controller e a Model estão corretas com todos os SQL / INNER JOIN.
Abaixo posto o código que gero o Relatório.
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
//Função para limitar o tamanho de caracteres
function limitar($string, $tamanho, $encode = 'UTF-8') {
$string = mb_substr($string, 0, $tamanho, $encode);
return $string;
}
class PDF extends FPDF{
// Page header
function Header(){
$corLin = $this->SetFillColor(144, 144, 144);
$this->Image('assets/img/img_logo.png',5,5,15);
$this->SetFont('Arial', '', 9);
$this->SetTextColor(35,35,35);
$this->Cell(285, 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(270,5,utf8_decode('VENDAS'),0,0,'C');
$this->Ln(7);
$this->Cell(80,5,'',0,0);
$this->SetFont('Arial','',12);
$this->SetTextColor(35,35,35);
$this->Cell(10,5,utf8_decode('por:'),0,0,'L');
$this->SetFont('Arial','B',12);
$this->Cell(30,5, utf8_decode('Todas'),0,0,'L');
$this->Ln(10);
$this->Cell(1,0,'',0,0);
$this->Cell(280,1,$corLin,0,0,'',1); //Muda a cor da linha
$this->Ln();
}
function titulo($vdas){
if(!$vdas){
$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('Nenhum Registro foi encontrado na Base de Dados.'),0,0,'L');
$this->SetTextColor(0,0,0);
$this->Ln(9);
} else {
$corLin = $this->SetFillColor(33, 160, 33);
foreach($vdas as $ct){
$this->Ln(2);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(23,10,utf8_decode('Razão Social:'),0,0,'L');
$this->SetFont('Arial','B',10);
$this->Cell(200,10, utf8_decode($ct->nomeCliente),0,0,'L');
$this->Ln(7);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(30,10,utf8_decode('Título da Cotação:'),0,0,'L');
$this->SetFont('Arial','B',10);
$this->Cell(200,10, utf8_decode($ct->vendaTitulo),0,0,'L');
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(21,10,utf8_decode('Cotação nº.:'),0,0,'L');
$this->SetFont('Arial','B',10);
$this->Cell(25,10,$ct->vendaNumber,0,0,'L');
$this->SetTextColor(0,0,0);
if($ct->vendaObservacao != "") {
$this->Ln(-3);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',10);
$this->Cell(33,10,utf8_decode('Observação:'),0,0,'L');
$this->SetFont('Arial','B',10);
$this->Ln(2.5); //Defina altura da Célula
$this->SetX(33); //Fixa a posição INÍCIO do texto
$this->MultiCell(252,5,utf8_decode($ct->vendaObservacao),0,'J', 0);
$this->Ln(1);
}
$this->Ln(3);
$this->Cell(1,5,'',0,0);
$corLin = $this->SetFillColor(33, 160, 33);
$this->Cell(280,1,$corLin,0,0,'',1); //Muda a cor da linha
$this->Ln(3);
}//Fim Foreach
}//Fim do 1º.IF
}
function conteudo($clients,$itens){
if(!$clients){
$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('Nenhum Registro foi encontrado na Base de Dados.'),0,0,'L');
$this->SetTextColor(0,0,0);
$this->Ln(9);
} else {
foreach($clients as $fr){
//Verifica se o campo COMPLEMENTO existe dados informados
if($fr->complCl == ""){ $compl = ''; } else { $compl = ' - '.$fr->complCl; }
$this->Ln(2);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',9);
$this->Cell(20,10,utf8_decode('Código:'),0,0,'L');
$this->Cell(180,10,utf8_decode('Razão Social:'),0,0,'L');
$this->Cell(45,10,utf8_decode('CNPJ:'),0,0,'L');
$this->Cell(34,10,utf8_decode('Inscrição Estadual:'),0,0,'L');
$this->Ln(3.5);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','B',9);
$this->Cell(20,10,str_pad($fr->idClientes,'5','0', STR_PAD_LEFT),0,0,'L');
$this->Cell(180,10,utf8_decode($fr->nomeCliente),0,0,'L');
$this->Cell(45,10,utf8_decode($fr->cnpj),0,0,'L');
$this->Cell(34,10,utf8_decode($fr->inscrEst),0,0,'L');
$this->Ln(4);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',9);
$this->Cell(130,10,utf8_decode('Endereço:'),0,0,'L');
$this->Cell(70,10,utf8_decode('Bairro:'),0,0,'L');
$this->Cell(54,10,utf8_decode('Cidade/UF:'),0,0,'L');
$this->Cell(30,10,utf8_decode('CEP:'),0,0,'L');
$this->Ln(3.5);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','B',9);
$this->Cell(130,10,utf8_decode($fr->enderecoCl).', n.'.$fr->numeroCl.utf8_decode($compl),0,0,'L');
$this->Cell(70,10,utf8_decode($fr->bairroCl),0,0,'L');
$this->Cell(54,10,utf8_decode($fr->cidadeCl.' / '.$fr->estadoCl),0,0,'L');
$this->Cell(30,10,$fr->cepCl,0,0,'L');
$this->Ln(4);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',9);
$this->Cell(25,10,utf8_decode('Telefone:'),0,0,'L');
$this->Cell(105,10,utf8_decode('E-mail:'),0,0,'L');
$this->Cell(30,10,utf8_decode('Prazo de Entrega:'),0,0,'L');
$this->Cell(118,10,utf8_decode('Condição de Pagamento'),0,0,'L');
$this->Ln(3.5);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','B',9);
$this->Cell(25,10,$fr->telefoneCl,0,0,'L');
$this->Cell(105,10,utf8_decode($fr->emailCl),0,0,'L');
$this->Cell(30,10,utf8_decode($fr->przEntr).' - dia(s)',0,0,'L');
$this->Cell(118,10,$fr->descricao.' - dias',0,0,'L');
if($fr->obsFatur != NULL || $fr->refVenda != NULL) {
$this->Ln(5);
$this->Cell(2,5,'',0,0);
$this->SetFont('Arial','',9);
$this->Cell(280,10,utf8_decode('Observação:'),0,0,'L');
$this->SetFont('Arial','B',9);
$this->Ln(2.5); //Defina altura da Célula
$this->SetX(33); //Fixa a posição INÍCIO do texto
$this->MultiCell(252,5,utf8_decode($fr->obsFatur).' '.utf8_decode($fr->refVenda),0,'J', 0);
$this->Ln(2);
} else {
$this->Ln();
}
//Monta a Tabela
$this->Ln(1);
$this->SetFillColor(107, 181, 148);
$this->SetDrawColor(160,160,160); //Muda a Cor das Bordas
$this->SetFont('Arial','B',9);
$this->Cell(5,5,utf8_decode('#'),0,0,'C',1);
$this->Cell(15,5,utf8_decode('Código'),0,0,'C',1);
$this->Cell(95,5,utf8_decode('Descrição'),0,0,'C',1);
$this->Cell(45,5,'Marca',0,0,'C',1);
$this->Cell(17,5,'ESP',0,0,'C',1);
$this->Cell(25,5,'Qtde',0,0,'C',1);
$this->Cell(35,5,'Vr. Unit.',0,0,'C',1);
$this->Cell(40,5,'Vr. Total',0,0,'C',1);
$this->Ln();
/*
* O erro acontece apartir dessas Linhas de Comando
*/
$soma = 0;
foreach($itens->result() as $ds){
$total = $ds->respQtde * $ds->respVlrunit;
$soma += $total;
$this->SetFont('Arial','',8);
$this->Cell(5,6,$ds->clientes_idClientes,1,0,'C');
$this->Cell(15,6,$ds->codProduto,1,0,'C');
$this->Cell(95,6,limitar(utf8_decode($ds->prdDesc),50),1,0,'L');
$this->Cell(45,6,limitar(utf8_decode($ds->respMarca),25),1,0,'L');
$this->Cell(17,6,$ds->respEspecie,1,0,'C');
$this->Cell(25,6,$ds->respQtde,1,0,'C');
$this->Cell(35,6,number_format($ds->respVlrunit, 2, ",", "."),1,0,'R');
$this->Cell(40,6,number_format($total, 2, ",", "."),1,0,'R');
$this->Ln();
}
//Total dos Itens que cada Fornecedor Ganhou
$this->Ln(1);
$this->SetFillColor(217, 213, 213);
$this->SetTextColor(0,0,0);
$this->SetFont('Arial','B',9);
$this->Cell(237,6,'Total: ',1,0,'R',1);
$this->SetFont('Arial','B',9);
$this->Cell(40,6, number_format($soma, 2, ",", "."),1,0,'R',1);
$this->Ln(5);
}//Fim do Foreach-forn
}//Fim do 1.IF
}
// Page footer
function Footer(){
$this->SetY(-15);
$this->SetFont('Arial','',9);
$this->Cell(0,10,utf8_decode('WEB sistemas'),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('Vendas'));
$pdf->AddPage('L','A4',0);
$pdf->SetFont('Times','',12);
$pdf->titulo($vdas);
$pdf->conteudo($clients,$itens);
$pdf->Output('Vendas_encerrada.'.'pdf',"I");
?>
Tentei adicionar essa linhas de Comando, mas infelizmente o Sistema acusa erro nesse comando **$this->db->query** principalmente em **->db**. Não entendi o porque desse erro.
<?php
$query = $this->db->query("SELECT ct.idVendas, ct.clientes_idClientes, ct.respEspecie, ct.respMarca, ct.respAnalise,
ct.respQtde, ct.respIdvda, ct.respProduto, pr.idProdutos, pr.codPrdClie, pr.prdDescr, pr.clientes_idClientes
FROM vendas ct
INNER JOIN produtos pr ON pr.codPrdClie = ct.respProduto
WHERE ct.clientes_idClientes = '$clie'
AND ct.respIdvda = '$cotnum'
AND ct.respAnalise = '1'
ORDER BY ct.respProduto ");
foreach ($query->result() as $row){
$idrp = $row->idVendas;
$codg = $row->codPrdClie;
$desc = $row->prdDescr;
$espc = $row->respEspecie;
$qtde = $row->respQtde;
$marc = $row->respMarca;
}
?>
Agradeço a todos.
Atenciosamente,
CesarCarregando comentários...