Last active
April 20, 2024 01:32
-
-
Save carlosleonam/8eff356ab1c2f8c2779766b56d928303 to your computer and use it in GitHub Desktop.
Modelo Duplicata com 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 | |
/** | |
* DuplicataReport Report | |
* @author <your name here> | |
*/ | |
include_once('vendor/tecnickcom/tcpdf/tcpdf_include.php'); | |
class DuplicataReport 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.'/duplicata_'.$param['ids'][0].'.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 | |
{ | |
if ((isset($param['ids'])) and (!empty($param['ids']))) { | |
} | |
TTransaction::open('tutorerpdfe'); | |
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); | |
$linha = 8; | |
$i=0; | |
foreach ($param['ids'] as $ids) { | |
$key = $ids; | |
$i++; | |
if ($i>1) {$linha=$linha+130;} | |
$duplicata = ContaReceber::where('id', '=', $key)->load(); | |
$pdf->SetMargins( 10, 10, 10 ); | |
$pdf->SetFooterMargin(0); | |
$pdf->setPrintHeader(false); | |
$pdf->setPrintFooter(false); | |
$pdf->SetAuthor('Agape World Informatica Ltda'); | |
$pdf->SetTitle('Duplicata'); | |
$pdf->SetSubject('TutorERPDFe'); | |
// set font | |
$pdf->SetFont('times', '', 9); | |
if ($i==1) { $pdf->AddPage(); }; | |
if ($linha > 260) { | |
$linha = 10; | |
$pdf->AddPage(); | |
} $ph = $pdf->GetPageHeight(); | |
$pw = $pdf->GetPageWidth(); | |
$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)); | |
$style_rounded = array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128)); | |
$pdf->SetLineStyle($style_rounded); | |
//$pdf->SetDrawColor(100); | |
$pdf->SetFillColor(255, 255, 255); | |
$pdf->SetLineWidth(0.2); | |
$pdf->SetTextColor(0,0,0); | |
$pdf->SetXY(8,$linha); | |
$pdf->RoundedRect(8, $linha+2, 195, 24, 1.50, '1111'); | |
$pdf->Line(8,$linha+32,108,$linha+32); | |
$pdf->Line(8,$linha+37,138,$linha+37); | |
$pdf->Line(30,$linha+32,30,$linha+45); | |
$pdf->Line(56,$linha+27,56,$linha+45); | |
$pdf->Line(82,$linha+32,82,$linha+45); | |
$pdf->Line(108,$linha+27,108,$linha+45); | |
$pdf->Line(160,$linha+2,160,$linha+26); | |
$pdf->RoundedRect(8, $linha+27, 130, 18, 1.50, '1111'); | |
$pdf->RoundedRect(28, $linha+46, 110, 18, 1.50, '1111'); | |
$pdf->RoundedRect(139, $linha+27, 64, 37, 1.50, '1111'); | |
$pdf->RoundedRect(28, $linha+65, 110, 27, 1.50, '1111'); | |
$pdf->RoundedRect(139, $linha+65, 64, 27, 1.50, '1111'); | |
$pdf->Line(139,$linha+74,203,$linha+74); | |
$pdf->Line(139,$linha+83,203,$linha+83); | |
$pdf->RoundedRect(28, $linha+93, 175,10, 1.50, '1111'); | |
$pdf->RoundedRect(28, $linha+104, 175,17, 1.50, '1111'); | |
$pdf->RoundedRect(8, $linha+46, 19, 75, 1.50, '1111'); | |
$pdf->SetXY(15,$linha+102); | |
$pdf->StartTransform(); | |
$pdf->Rotate(90); | |
$pdf->SetFont('times','',7); | |
$pdf->SetTextColor(0,0,102); | |
$pdf->Cell(05, 21, 'ASSINATURA DO EMITENTE', 0, 0,'L',0,''); | |
$pdf->StopTransform(); | |
$pdf->Line(24,$linha+48,24,$linha+119); | |
//cabecalho dados da empresa data/hora | |
$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')); | |
$image_file = 'files/images/empresa/'.'admin.jpg'; | |
$pdf->Image($image_file, 10, $linha+4, 20, '', 'JPG', '', 'T', false, 250, '', false, false, 0, false, false, false); | |
$pdf->SetFont('times', 'B', 12); | |
$tDate= new DateTime(); | |
$pdf->Cell(115, 4, $empresa->srazaosocial, 0, 1, 'C'); | |
$pdf->SetFont('times', 'B', 8); | |
$pdf->Cell(150, 4, $empresa->senderecologradouro.','.$empresa->sendereconumero, 0, 1, 'C'); | |
$pdf->Cell(150, 4, $empresa->cidade->nome.'-'.$empresa->cidade->estado->uf, 0, 1, 'C'); | |
$pdf->Cell(140, 4, 'CNPJ: '.$empresa->scnpj.' - '.'I.E.: '.$empresa->sinscricaoestadual, 0, 1, 'C'); | |
$txt = 'Fone: '.$empresa->stelefone.' - '.'Celular: '.$empresa->scelular.' - '.'Email: '.$empresa->semail; | |
$pdf->Cell(150, 4,$txt, 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(8,$linha+7); | |
$pdf->SetFont('times','B',8); | |
$pdf->Cell(170,5,"Date: ",0,0,'R'); | |
$pdf->setFont('times','',8); | |
$pdf->Cell(165,5,$tDate->format('d/m/Y'),0,1,'L'); | |
$pdf->SetFont('times','B',8); | |
$pdf->SetXY(8,$linha+12); | |
$pdf->Cell(170,5,"Hora: ",0,0,'R'); | |
$pdf->setFont('times','',8); | |
$pdf->Cell(165,5,$tDate->format('H:i'),0,1,'L'); | |
$pdf->SetFont('times','',8); | |
$pdf->SetXY(10,$linha+27); | |
$pdf->Cell(40, 4,'F A T U R A', 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(10,$linha+32); | |
$pdf->Cell(20, 4,'VALOR R$', 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(10,$linha+32); | |
$pdf->Cell(65, 4,'NÚMERO', 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(10,$linha+32); | |
$pdf->Cell(115, 4,'VALOR R$', 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(10,$linha+32); | |
$pdf->Cell(165, 4,'NÚMERO', 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(28,$linha+27); | |
$pdf->Cell(105, 4,'D U P L I C A T A', 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(142,$linha+27); | |
$pdf->MultiCell(100, 4,"PARA USO DA INSTITUIÇÃO FINANCEIRA", 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetXY(38,$linha+30); | |
$pdf->Cell(170, 4,'VENCIMENTO', 0, 0, 'C', 0, '', 1); | |
$pdf->SetFont('times','',8); | |
$pdf->SetXY(30,$linha+47); | |
$pdf->Cell(30, 4,'DESCONTO DE:', 0, 0, 'L', 0, '', 1); | |
$pdf->Cell(30, 4,'% S/', 0, 0, 'L', 0, '', 1); | |
$pdf->Cell(15, 4,'PGTO ATÉ:', 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(30,$linha+52); | |
$pdf->Cell(40, 4,'COND. ESPECIAIS:', 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(30,$linha+57); | |
$pdf->Cell(40, 4,'ENCARGOS FINANCEIROS:', 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(30,$linha+67); | |
$pdf->Cell(22, 4,'NOME DO SACADO:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(139,$linha+67); | |
$pdf->Cell(22, 4,'CÓD. CLIENTE:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(30,$linha+72); | |
$pdf->Cell(22, 4,'ENDERECO:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(139,$linha+76); | |
$pdf->Cell(22, 4,'VENDEDOR:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(30,$linha+77); | |
$pdf->Cell(22, 4,'MUNICIPIO:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(95,$linha+77); | |
$pdf->Cell(25, 4,'CEP:', 0, 0, 'L', 0, '', 1); | |
$pdf->Cell(15, 4,'UF:', 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(30,$linha+82); | |
$pdf->Cell(22, 4,'PRAÇAO DE PAGTO:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(139,$linha+86); | |
$pdf->Cell(22, 4,'COBRANÇA:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(95,$linha+82); | |
$pdf->Cell(25, 4,'CEP:', 0, 0, 'L', 0, '', 1); | |
$pdf->Cell(15, 4,'UF:', 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(30,$linha+87); | |
$pdf->Cell(22, 4,'CNPJ/CPF:', 0, 0, 'R', 0, '', 1); | |
$pdf->SetXY(93,$linha+87); | |
$pdf->Cell(25, 4,'IE/RG:', 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(28,$linha+95); | |
$pdf->MultiCell(30, 4,"VALOR POR EXTENSO:", 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetFont('times','',7); | |
$pdf->SetXY(28,$linha+104); | |
$pdf->MultiCell(180, 4,"RECONHEÇO(EMOS) A EXATIDÃO DESTA DUPLICATA DE VENDA MERCANTIL, NA IMPORTÂNCIA ACIMA, QUE PAGEREI(EMOS) À", 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetXY(107,$linha+107); | |
$pdf->MultiCell(95, 4,",OU À SUA ORDEM NA PRAÇA E VENCIMENTO ACIMA INDICADOS.", 0, 'R', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetXY(28,$linha+114); | |
$pdf->MultiCell(40, 4,"___/__/____", 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetXY(32,$linha+118); | |
$pdf->MultiCell(40, 4,"DATA DO ACEITE", 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetXY(107,$linha+114); | |
$pdf->MultiCell(110, 4,"___________________", 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetXY(127,$linha+118); | |
$pdf->MultiCell(40, 4,"ASSINATURA DO SACADO", 0, 'L', 0, 1, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetFont('helvetica','B',8); | |
if ($duplicata) | |
{ | |
foreach ($duplicata as $r) | |
{ | |
$pdf->SetXY(10,$linha+39); | |
$pdf->Cell(20, 4,number_format($r->valor, 2, ',', ' '), 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(10,$linha+39); | |
$pdf->Cell(65, 4,$r->documento, 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(10,$linha+39); | |
$pdf->Cell(115, 4,number_format($r->valor, 2, ',', ' '), 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(10,$linha+39); | |
$pdf->Cell(165, 4,$r->documento, 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(38,$linha+39); | |
$pdf->Cell(170, 4,Uteis::awi_formataData($r->dt_vencimento), 0, 0, 'C', 0, '', 1); | |
$pdf->SetXY(51,$linha+67); | |
$pdf->Cell(59, 4,$r->pessoa->nome, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(51,$linha+72); | |
$pdf->Cell(59, 4,$r->pessoa->logradouro.','.$r->pessoa->numero, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(51,$linha+77); | |
$pdf->Cell(59, 4,$r->pessoa->cidade->nome, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(102,$linha+77); | |
$pdf->Cell(25, 4,$r->pessoa->cep, 0, 0, 'L', 0, '', 1); | |
$pdf->Cell(20, 4,$r->pessoa->cidade->estado->uf, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(51,$linha+82); | |
$pdf->Cell(59, 4,$r->pessoa->cidade->nome, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(102,$linha+82); | |
$pdf->Cell(25, 4,$r->pessoa->cep, 0, 0, 'L', 0, '', 1); | |
$pdf->Cell(20, 4,$r->pessoa->cidade->estado->uf, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(51,$linha+87); | |
$pdf->Cell(59, 4,$r->pessoa->codigo_nacional, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(102,$linha+87); | |
$pdf->Cell(25, 4,$r->pessoa->codigo_estadual, 0, 0, 'L', 0, '', 1); | |
$pdf->SetXY(47,$linha+95); | |
$txt = trim(Uteis::awi_valorExtenso($r->valor)); | |
$l=$pdf->getNumLines( $txt,95, false, true, '', 0 ); | |
$pdf->MultiCell(160, 4,$txt, 0, 'L', 1, 0, '', '', true, 0, false, true, 0, 'M'); | |
$pdf->SetXY(28,$linha+107); | |
$pdf->Cell(80, 4,$empresa->srazaosocial, 0, 0, 'L', 0, '', 1); | |
} | |
} | |
} | |
$pathsub = TSession::getValue('TutorERPDFe_Login_Empresa_scnpj'); | |
$output = '/var/www/html/tutorerpdfe/app/output/'.$pathsub.'/duplicata_'.$param['ids'][0].'.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) |
Author
carlosleonam
commented
Oct 21, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment