Skip to content

Instantly share code, notes, and snippets.

@carlosleonam
Last active October 21, 2021 12:23
Show Gist options
  • Save carlosleonam/19204fa51a4f39c03898564c3c8b8dd8 to your computer and use it in GitHub Desktop.
Save carlosleonam/19204fa51a4f39c03898564c3c8b8dd8 to your computer and use it in GitHub Desktop.
Recibo com TCPDF (by Paulo Guimarães)
<?php
class ReciboReport extends TWindow
{
/**
* Generate the report
*/
public function __construct($param)
{
parent::__construct();
parent::setTitle(_t('Window with embedded PDF'));
parent::setSize(0.8, 0.8);
$pathsub = TSession::getValue('TutorERPDFe_Login_Empresa_scnpj');
$output = 'app/output/'.$pathsub.'/recibo_'.$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);
}
function onGenerate($param)
{
try
{
TTransaction::open('tutorerpdfe');
$key = $param['key'];
$recibo = Recibo::where('id', '=', $key)->load();
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetMargins( 10, 10, 10 );
$pdf->SetFooterMargin(0);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$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();
// $pdf->SetTextColor(0,0,102);
// $pdf->SetFont('helvetica','B',14);
// $pdf->Cell(150,45,"Pedido de Venda ",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->SetDrawColor(100);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetXY(8,8);
$pdf->Rect(8, 10, 65, 78, 'D');
$pdf->SetXY(10,10);
$pdf->Rect(75, 10, 128, 78, 'D');
// $pdf->SetFillColor(255, 0, 0);
$style = array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => '4,4', 'phase' => 10, 'color' => array(255, 0, 0));
$style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128));
$pdf->Line( 74, 95, 74, 05, $style);
$pdf->SetLineWidth(0.3);
$pdf->SetLineStyle($style5);
// $pdf->Line( 74,95,74,05);
$pdf->SetXY(10,13);
$pdf->SetFont('helvetica','B',10);
$pdf->setCellPaddings(1,1,1,1);
if ($recibo)
{
foreach ($recibo as $r)
{
$pdf->SetTextColor(255,0,0);
$pdf->MultiCell(60, 5,"COMPROVANTE DE ENTREGA DE RECIBO", 0, 'C', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->SetTextColor(0,0,0);
// $pdf->MultiCell(60, 5,"Recibo Nr.: ".str_pad($r->id, 5, '0', STR_PAD_LEFT), 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(30, 5,"Recibo Nr.: ", 1, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(30, 5,str_pad($r->id, 5, '0', STR_PAD_LEFT), 1, 'R', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(30, 5,"R$ Valor.:", 1, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(30, 5,Uteis::awi_numeroBrasil($r->valor), 1, 'R', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(60, 5,"Recebemos de ".$r->sfavorecido, 1, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(30, 5,"Documento Nr", 1, 'L', 1, 0, '', '', true, 1, false, true, 0, 'M');
$pdf->MultiCell(30, 5,$r->sdocumentofavorecido, 1, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(60, 5,"Referente : ".$r->sreferente, 1, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(30, 5,"Data :", 1, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(30, 5,Uteis::awi_formataData($r->dataemissao), 1, 'C', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->SetXY(10,10);
$pdf->Rect(150, 12, 50, 15, 'D');
$pdf->SetXY(10,13);
$pdf->SetFont('helvetica','B',18);
$pdf->MultiCell(220, 10,"RECIBO", 0, 'C', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',10);
$pdf->SetXY(150,13);
$pdf->MultiCell(25, 4,"Recibo Nr.: ", 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->MultiCell(25, 4,str_pad($r->id, 5, '0', STR_PAD_LEFT), 0, 'R', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->SetXY(150,19);
$pdf->MultiCell(25, 4,"R$ Valor.:", 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetTextColor(255,0,0);
$pdf->MultiCell(25, 4,Uteis::awi_numeroBrasil($r->valor), 0, 'R', 0, 1, '', '', true, 0, false, true, 0, 'M');
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(10,10);
$pdf->Rect(77, 28, 123, 30, 'D');
$pdf->SetXY(78,28);
$pdf->SetFont('helvetica','',9);
$pdf->MultiCell(26, 4,"Recebemos de", 0, 'R', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',9);
$pdf->Cell(90, 4,$r->sfavorecido, 0, 0, 'L', 0, '', 1);
$pdf->SetXY(78,32);
$pdf->SetFont('helvetica','',9);
$pdf->MultiCell(26, 4,"Endereço", 0, 'R', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',9);
$txt = $r->senderecologradouro.','.$r->sendereconumero;
$pdf->Cell(90, 4,$txt, 0, 0, 'L', 0, '', 1);
$pdf->SetXY(104,36);
$txt = $r->cidade->nome.'-'.$r->cidade->estado->uf.' - Documento: '.$r->sdocumentofavorecido;
$pdf->Cell(90, 4,$txt, 0, 0, 'L', 0, '', 1);
$pdf->SetXY(78,40);
$pdf->SetFont('helvetica','',9);
$pdf->MultiCell(26, 4,"A importância de", 0, 'R', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',8);
$txt = trim(Uteis::awi_valorExtenso($r->valor));
$l=$pdf->getNumLines( $txt,95, false, true, '', 0 );
$pdf->MultiCell(95, 4,$txt, 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetXY(78,40+($l*4));
$pdf->SetFont('helvetica','',10);
$pdf->MultiCell(26, 4,"Referente à", 0, 'R', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',8);
$pdf->MultiCell(94, 4,$r->sreferente, 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetXY(105,57);
$pdf->SetFont('times','',8);
$pdf->MultiCell(230, 4,"PARA MAIOR CLAREZA FIRMAMOS O PRESENTE", 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetXY(150,61);
$pdf->SetFont('times','',8);
$pdf->MultiCell(220, 4,$r->cidade->nome.', '.Uteis::awi_dataextenso($r->dataemissao).'.' , 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetXY(78,67);
$pdf->SetFont('helvetica','',9);
$pdf->MultiCell(20, 4,"Emitente: ", 0, 'R', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',9);
$pdf->Cell(90, 4,$r->semitente, 0, 0, 'L', 0, '', 1);
$pdf->SetFont('helvetica','',9);
$pdf->SetXY(78,71);
$pdf->MultiCell(20, 4,"Documento: ", 0, 'R', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',9);
$pdf->Cell(90, 4,$r->sdocumentoemitente, 0, 0, 'L', 0, '', 1);
$pdf->SetXY(78,82);
$pdf->MultiCell(20, 4,"Assinatura: ", 0, 'R', 1, 0, '', '', true, 0, false, true, 0, 'M');
$pdf->SetFont('helvetica','B',9);
$pdf->Cell(100, 4,'______________________________', 0, 0, 'L', 0, '', 1);
}
$pathsub = TSession::getValue('TutorERPDFe_Login_Empresa_scnpj');
$output = '/var/www/html/tutorerpdfe/app/output/'.$pathsub.'/recibo_'.$key.'.pdf';
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)
@carlosleonam
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment