Created
October 21, 2021 12:30
-
-
Save carlosleonam/8d7573854260384af80d7ac83dc90fca to your computer and use it in GitHub Desktop.
Relatório de Pediidos em TCPDF ( by Paulo Guimarães )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PedidosReport Report | |
* @author <your name here> | |
*/ | |
include_once('vendor/tecnickcom/tcpdf/tcpdf_include.php'); | |
class AWIPDF extends TCPDF | |
{ | |
function Header() | |
{ | |
TTransaction::open('tutorerpdfe'); | |
$login = TSession::getValue('login'); //nome de login do usuario | |
$userid = TSession::getValue('userid'); //id do usuario | |
$username = TSession::getValue('username'); | |
$userunitids = TSession::getValue('userunitids'); | |
$unit = new SystemUnit($userunitids); | |
$empresa = Empresa::find(TSession::getValue('TutorERPDFe_Login_Empresa_id')); | |
TTransaction::close(); | |
$y=0; | |
$x=10; | |
$pathsub = TSession::getValue('TutorERPDFe_Subdominio'); // get items from session | |
$image_file = 'files/images/'.$pathsub.'/empresa/'.'admin.jpg'; | |
$this->Image($image_file, 10, 10, 20, '', 'JPG', '', 'T', false, 250, '', false, false, 0, false, false, false); | |
$this->SetFont('times', 'B', 12); | |
$tDate= new DateTime(); | |
$this->SetTextColor(0,0,102); | |
$this->Cell(120, 4, $empresa->srazaosocial, 0, 1, 'C'); | |
$this->SetFont('times', 'B', 8); | |
$this->SetXY($x,$y+15); | |
$this->Cell(160, 4, $empresa->senderecologradouro.','.$empresa->sendereconumero, 0, 1, 'C'); | |
$this->SetXY($x,$y+19); | |
$this->Cell(160, 4,'CNNPJ: '.$empresa->scnpj.' - '.'I.E.: '.$empresa->sinscricaoestadual, 0, 1, 'C'); | |
$this->SetXY($x,$y+23); | |
$this->Cell(160, 4, 'Fone: '.$empresa->stelefone.' - '.'Celular: '.$empresa->scelular.' - '.'Email: '.$empresa->semail, 0, 1, 'C'); | |
$this->SetXY($x,10); | |
$this->SetFont('times','B',8); | |
$this->Cell(165,4,"Date: ",0,0,'R'); | |
$this->setFont('times','',8); | |
$this->Cell(165,4,$tDate->format('d/m/Y'),0,1,'L'); | |
$this->SetFont('times','B',8); | |
$this->Cell(165,4,"Hora: ",0,0,'R'); | |
$this->setFont('times','',8); | |
$this->Cell(165,4,$tDate->format('H:i'),0,1,'L'); | |
$this->SetFont('times','B',8); | |
$this->Cell(165,4,"Usuário: ",0,0,'R'); | |
$this->setFont('times','',8); | |
$this->Cell(165,4,$login,0,0,'L'); | |
$this->SetTextColor(0,0,0); | |
$this->SetLineWidth(0.1); | |
$this->Line(10,30,195,30); | |
$this->ln( 5 ); | |
} | |
function Footer() | |
{ | |
//move pionter at the bottom of the page | |
$this->SetY(144); | |
//set font to helvetica, Bold, size 10 | |
$this->SetFont( 'times', 'B', 6 ); | |
$this->SetTextColor( 0, 0, 102 ); | |
$this->Cell( 10, 4, 'TutorERPDFe - www.agapeworld.com.br', 0, 0, 'L', false, 'http://www.agapeworld.com.br', 0, true, 'T', 'M' ); | |
//set font color to gray | |
// $this->SetTextColor( 150, 150, 150 ); | |
//write Page No | |
$this->SetLineWidth(0.1); | |
$this->Line(10,$this->getY(),195,$this->getY()); | |
$this->Cell( 180, 4, 'Página Nr: ' . $this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, 0, 'R' ); | |
} | |
} | |
class PedidosReportA4 extends TWindow | |
{ | |
/** | |
* Generate the report | |
*/ | |
public function __construct($param) | |
{ | |
parent::__construct(); | |
$pathsub = TSession::getValue('TutorERPDFe_Login_Empresa_scnpj'); // get items from session | |
parent::setTitle(_t('Window with embedded PDF')); | |
parent::setSize(0.8, 0.8); | |
$output = 'app/output/'.$pathsub.'/pedido_'.$param['key'].'.pdf'; | |
$object = new TElement('object'); | |
$object->data = $output; | |
$object->type = 'application/pdf'; | |
$object->style = "width: 100%; height:calc(100% - 10px)"; | |
parent::add($object); | |
if (!isset($param['email'])) { | |
} else { | |
if (filter_var($param['email'], FILTER_VALIDATE_EMAIL)) { | |
$retorno = TNfe::EmailPedido($param['key'],$output,$param['email']); | |
} else { | |
new TMessage('erro', 'Email Digitado Inválido !' ); | |
} | |
} | |
} | |
function onGenerate($param) | |
{ | |
try | |
{ | |
TTransaction::open('tutorerpdfe'); | |
$key = $param['key']; | |
$pedido = Pedidos::where('id', '=', $key)->load(); | |
$pedidoitem = ViewPedidosItem::where('pedidos_id', '=', $key)->load(); | |
$pedidofatura = PedidosFatura::where('pedidos_id', '=', $key)-> | |
orderby('dt_vencimento','DESC')->load(); | |
$pdf = new AWIPDF('P', 'mm', 'A4', true, 'UTF-8', false); | |
//$pageLayout = array( 210 , 148 ); | |
//$pdf = new AWIPDF('P', 'mm', $pageLayout, true, 'UTF-8', false); | |
$pdf->SetMargins( 10, 10, 10 ); | |
$pdf->setFooterMargin(0); | |
$pdf->SetHeaderMargin(0); | |
$pdf->SetAuthor('Agape World Informatica Ltda'); | |
$pdf->SetTitle('Pedido de Venda'); | |
$pdf->SetSubject('TutorERPDFe'); | |
// set font | |
$pdf->SetFont('times', '', 9); | |
$pdf->AddPage(); | |
$ph = $pdf->GetPageHeight(); | |
$pw = $pdf->GetPageWidth(); | |
if ($pedido) | |
{ | |
foreach ($pedido as $p) | |
{ | |
$pdf->SetTextColor(0,0,102); | |
$pdf->SetFont('helvetica','B',14); | |
$pdf->Cell(150,45,"Pedido - ".$p->tipo,0,0,'C'); | |
$linhas = 20; // Máximo de linhas por página | |
$count_lines = 0; // Contagem de linhas na página | |
$pdf->setCellHeightRatio(1.0); | |
$pdf->SetFont('helvetica','B',12); | |
$pdf->Cell(20,45,"Nr.:",0,0,'C'); | |
$pdf->Cell(1,45, str_pad($p->id, 5, '0', STR_PAD_LEFT) ,0,0,'C'); | |
$pdf->SetTextColor(0,0,0); | |
$pdf->SetLineWidth(0.1); | |
$pdf->Line(10,35,195,35); | |
$pdf->Ln(6); | |
$pdf->SetY(36); | |
//nome | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell ( 25, 4, 'Nome:', 0, 0, 'R', false, '', 0, true, 'T', 'M' ); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell ( 25, 4, $p->pessoa->nome, 0, 0, 'L', false, '', 0, true, 'T', 'M' ); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->SetTextColor(255,0,0); | |
$pdf->Cell ( 132, 4,'Data Pedido: '.Uteis::awi_formataData($p->datapedido), 0, 1, 'R', false, '', 0, true, 'T', 'M' ); | |
$pdf->SetTextColor(0,0,0); | |
$pdf->Cell ( 25, 4, 'E-mail:', 0, 0, 'R', false, '', 0, true, 'T', 'M' ); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell ( 70, 4, $p->pessoa->email, 0, 0, 'L', false, '', 0, true, 'T', 'M' ); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(25,4,"Cond. Pgto:",0,0,'R'); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell(25,4,$p->condicaopagamento->sdescricao,0,1,'L'); | |
//fone/celular | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(25,4,"Telefone:",0,0,'R'); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell(25,4,$p->pessoa->celular,0,0,'L'); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(70,4,"Celular:",0,0,'R'); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell(70,4,$p->pessoa->fone,0,1,'L'); | |
//Endereço | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(25,4,"Endereco:",0,0,'R'); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell(25,4,$p->pessoa->logradouro,0,1,'L'); | |
//cep | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(25,4,"CEP:",0,0,'R'); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell(25,4,$p->pessoa->cep,0,0,'L'); | |
//cidade | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(70,4,"Cidade:",0,0,'R'); | |
$pdf->setFont('helvetica','',10); | |
$pdf->Cell(70,4,$p->pessoa->cidade->nome.' - '.$p->pessoa->cidade->estado->uf,0,0,'L'); | |
$pdf->SetXY(10,10); | |
$pdf->Cell(185,47,'',1,1,'P'); | |
} | |
$x = 0; | |
if ($pedidofatura) | |
{ | |
$pdf->setX(10); | |
$pdf->SetFont('helvetica','',8); | |
foreach ($pedidofatura as $pf) | |
{ | |
$x++; | |
$pdf->Cell(12,3,$pf->sfatura,0,0,'L'); | |
$pdf->Cell(17,3,Uteis::awi_formataData($pf->dt_vencimento),0,0,'L'); | |
$pdf->SetFont('helvetica','B',8); | |
$pdf->Cell(15,3,Uteis::awi_numeroBrasil($pf->nvalor),0,0,'R'); | |
$pdf->SetFont('helvetica','',8); | |
if ($x==4) { | |
$x=0; | |
$pdf->ln(); | |
} | |
} | |
} | |
if ($x<>0) { | |
$pdf->ln(); | |
} | |
//cabeçalho da tabela | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(125,05,'Produto',1,0,"L"); | |
$pdf->Cell(20,05,'Quantidade',1,0,"R"); | |
$pdf->Cell(20,05,'R$ Unitário',1,0,"R"); | |
$pdf->Cell(20,05,'R$ Total',1,1,"R"); | |
//linhas da tabela | |
$pdf->SetFont('helvetica','',9); | |
$pdf->setCellPaddings(1, 0, 1, 0); | |
$pdf->setCellMargins(0, 0, 0, 0); | |
$pdf->SetFillColor(255, 255, 255); | |
$pdf->SetXY(10,$pdf->getY()); | |
$pdf->SetAutoPageBreak(TRUE, 0); | |
$i=0; | |
foreach ($pedidoitem as $pi) | |
{ | |
$pdf->Cell(10 ,04,str_pad($pi->produto_id, 5, '0', STR_PAD_LEFT),0,0,"R"); | |
$y=$pdf->getY(); | |
$x=$pdf->getX(); | |
//print_r($pi); | |
$l=$pdf->getNumLines( $pi->sdescricao,120, false, true, '', 0 ); | |
$count_lines = $count_lines + $l; | |
// $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); | |
// $pdf->SetHeaderMargin(50); | |
$pdf->MultiCell(105, 4,$pi->sdescricao, 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M'); | |
// $pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM); | |
$lh=$pdf->getLastH( ); | |
$pdf->getLastH($lh ); | |
$pdf->SetXY(136,$y); | |
$pdf->MultiCell(20, 4,Uteis::awi_formata_numero_casas_br($pi->nquantidade,3), 0, 'R', 0,0); | |
$pdf->MultiCell(20, 4,Uteis::awi_formata_numero_casas_br($pi->nvalorunitario,3), 0, 'R', 0,0); | |
$pdf->MultiCell(20, 4,Uteis::awi_formata_numero_casas_br($pi->ntotalitem,2), 0, 'R', 0,0); | |
$pdf->SetXY(10,$y+($l*3.5)); | |
$pdf->SetLineWidth(0.1); | |
$pdf->Line(10,$pdf->getY(),195,$pdf->getY()); | |
if ($count_lines >= $linhas) { | |
$pdf->AddPage(); | |
$count_lines = 0; | |
$linhas = 25; | |
foreach ($pedido as $p) | |
{ | |
$pdf->SetTextColor(0,0,102); | |
$pdf->SetFont('helvetica','B',14); | |
$pdf->Cell(150,45,"Pedido de Venda ",0,0,'C'); | |
$pdf->SetFont('helvetica','B',12); | |
$pdf->Cell(20,45,"Nr.:",0,0,'C'); | |
$pdf->Cell(1,45, str_pad($p->id, 5, '0', STR_PAD_LEFT) ,0,0,'C'); | |
$pdf->SetTextColor(0,0,0); | |
$pdf->SetLineWidth(0.1); | |
$pdf->Line(10,35,195,35); | |
$pdf->Ln(6); | |
$pdf->SetY(36); | |
} | |
$pdf->SetX(10); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(125,04,'Produto id',1,0,"L"); | |
$pdf->Cell(20,04,'Quantidade',1,0,"R"); | |
$pdf->Cell(20,04,'R$ Unitário',1,0,"R"); | |
$pdf->Cell(20,04,'R$ Total',1,1,"R"); | |
$pdf->SetFont('helvetica','',9); | |
} | |
$pdf->ln(); | |
} | |
$pdf->Ln(05); | |
$pdf->SetXY(10,124); | |
$pdf->Rect(10, 124, 130, 12, 'D'); | |
$pdf->Rect(10, 136, 130, 6, 'D'); | |
$pdf->Rect(140, 124, 55, 18, 'D'); | |
//Observações | |
$pdf->SetXY(10,124); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(25,4,"Observações:",0,0,'L'); | |
$y = $pdf->getY(); | |
$x = $pdf->getX(); | |
$pdf->setFont('helvetica','',9); | |
$pdf->MultiCell(105,4,$p->observacao,0,'L',0,4); | |
foreach ($pedido as $p) | |
{ | |
$pdf->SetXY(24,137); | |
$pdf->SetFont('helvetica','B',8); | |
$pdf->Cell(9,4,"Assinatura:",0,0,'R'); | |
$pdf->setFont('times','B',8); | |
$pdf->Cell(65,4,'______________',0,0,'L'); | |
$pdf->Cell(5,4,"Data:",0,0,'R'); | |
$pdf->setFont('times','B',8); | |
$pdf->Cell(20,4,'_/_/__.',0,0,'L'); | |
$pdf->SetXY(165,125); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(10,4,"Total dos Produtos:",0,0,'R'); | |
$pdf->setFont('times','B',9); | |
$pdf->Cell(20,4,Uteis::awi_numeroBrasil($p->totalprodutos),0,0,'R'); | |
$pdf->SetXY(165,129); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(10,4,"Desconto(-):",0,0,'R'); | |
$pdf->setFont('times','B',9); | |
$pdf->Cell(20,4,Uteis::awi_numeroBrasil($p->desconto),0,0,'R'); | |
$pdf->SetXY(165,133); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(10,4,"Frete(+):",0,0,'R'); | |
$pdf->setFont('times','B',9); | |
$pdf->Cell(20,4,Uteis::awi_numeroBrasil($p->nfrete),0,0,'R'); | |
$pdf->SetXY(165,137); | |
$pdf->SetFont('helvetica','B',9); | |
$pdf->Cell(10,4,"Total do Pedido:",0,0,'R'); | |
$pdf->setFont('times','B',9); | |
$pdf->Cell(20,4,Uteis::awi_numeroBrasil($p->totalpedido),0,0,'R'); | |
} | |
$pathsub = TSession::getValue('TutorERPDFe_Login_Empresa_scnpj'); // get items from session | |
$output = '/var/www/html/tutorerpdfe/app/output/'.$pathsub.'/pedido_'.$key.'.pdf'; | |
//if (!file_exists("app/output/Cfop.{$format}") OR is_writable("app/output/Cfop.{$format}")) | |
// { | |
// $tr->save("app/output/Cfop.{$format}"); | |
// } | |
if (!file_exists($output) OR is_writable($output)) | |
{ | |
$pdf->Output($output,'F'); | |
chmod($output, 0777); | |
// parent::openFile($output); | |
} | |
else | |
{ | |
throw new Exception('Permissão negada: ' . $output); | |
} | |
} | |
TTransaction::close(); | |
} | |
catch (Exception $e) // in case of exception | |
{ | |
// shows the exception error message | |
new TMessage('error', $e->getMessage()); | |
// undo all pending operations | |
TTransaction::rollback(); | |
} | |
} | |
} | |
//rgb(255, 0, 0) - vermelho | |
//rgb(0, 0, 255) - azul | |
// rgb(255, 255, 0) - amarelo | |
// rgb(0, 255, 0) - verde | |
//rgb(128, 128, 128) - cinza | |
// rgb(0, 0, 0) - preto | |
//rgb(0, 0, 102) - navy | |
//rgb(255, 255, 179) - amarelo claro | |
//rgb(128, 204, 255) - azul rodape | |
// Cell( $w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M' ) | |
// $pdf= new MYPDF("P","mm","A4"); | |
// $orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false | |
//MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0) |
Author
carlosleonam
commented
Oct 21, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment