From f641c084244709813811cc9245b82eee5235b90a Mon Sep 17 00:00:00 2001 From: robmachado Date: Fri, 31 May 2024 14:38:02 -0300 Subject: [PATCH] Ajustes para o novo Danfe refatorado --- docs/Danfe2.md | 226 +++++++++ src/Common/NfeStd.php | 91 ++++ src/Legacy/FPDF/Fpdf.php | 224 ++++----- src/Legacy/Pdf.php | 3 +- src/NFe/Traits/TraitCanhotoNfe.php | 157 ++++++ src/NFe/Traits/TraitDadosAdicionaisNfe.php | 117 +++++ .../Traits/TraitDadosAdicionaisNfeOutras.php | 25 + src/NFe/Traits/TraitDestinatarioNfe.php | 169 +++++++ src/NFe/Traits/TraitDuplicatasNfe.php | 215 ++++++++ src/NFe/Traits/TraitHeaderNfe.php | 316 ++++++++++++ src/NFe/Traits/TraitImpostosNfe.php | 121 +++++ src/NFe/Traits/TraitItensNfe.php | 476 ++++++++++++++++++ .../Traits/TraitLocalRetiradaEntregaNfe.php | 140 ++++++ src/NFe/Traits/TraitRodapeNfe.php | 24 + src/NFe/Traits/TraitTransportadorNfe.php | 290 +++++++++++ src/NFe/Traits/TraitWaterMark.php | 76 +++ 16 files changed, 2557 insertions(+), 113 deletions(-) create mode 100644 docs/Danfe2.md create mode 100644 src/Common/NfeStd.php create mode 100644 src/NFe/Traits/TraitCanhotoNfe.php create mode 100644 src/NFe/Traits/TraitDadosAdicionaisNfe.php create mode 100644 src/NFe/Traits/TraitDadosAdicionaisNfeOutras.php create mode 100644 src/NFe/Traits/TraitDestinatarioNfe.php create mode 100644 src/NFe/Traits/TraitDuplicatasNfe.php create mode 100644 src/NFe/Traits/TraitHeaderNfe.php create mode 100644 src/NFe/Traits/TraitImpostosNfe.php create mode 100644 src/NFe/Traits/TraitItensNfe.php create mode 100644 src/NFe/Traits/TraitLocalRetiradaEntregaNfe.php create mode 100644 src/NFe/Traits/TraitRodapeNfe.php create mode 100644 src/NFe/Traits/TraitTransportadorNfe.php create mode 100644 src/NFe/Traits/TraitWaterMark.php diff --git a/docs/Danfe2.md b/docs/Danfe2.md new file mode 100644 index 00000000..3de98aa3 --- /dev/null +++ b/docs/Danfe2.md @@ -0,0 +1,226 @@ +# Danfe2 + +Classe que constroi o DANFE observando os paramêtros estabelecidos pela SEFAZ, com algums adicionais para facilitação de obtenção de informações para quem os recebe. + +> NOTA: exclusivo para XML de NFe (modelo 55) + +# Funções Publicas + +## Instanciação + +Na instanciação da classe DANFE é obrigatório a passagem do XML da NFe modelo 55. + +```php + + /** + * Construtor + * @param string $xml + * @throws \Exception + */ + //somente são aceitos documentos XML devidamente formados e apenas NFe modelo 55 com ou sem protocolo de autorização + $xml = file_exists(__DIR__. '/arquivo_xml_nfe_modelo_55.xml'); + $danfe2 = new Danfe2($xml); + +``` + +## Parametrização + +```php + + /** + * Define parametros de impressão + * Este método não necessita ser invocado pois é setado por padrão com as condições default + * use apenas se desejar alterar as condições default + * @param string $orientacao + * @param string $papel + * @param int $margSup + * @param int $margEsq + * @return void + */ + $orientacao = ''; //se deixar em branco será usada a orientação indicada no XML, default = '', opções 'P' ou 'L', qualquer outra opção será ignorada + $papel = 'A4'; //default = 'A4', opção 'LEGAL' => recomenda-se usar sempre A4, qualquer outra opção será ignorada + $margSup = 2; //default = 2, cuidado com margens muito grandes pois diminuem em excesso a área de impressão + $margEsq = 2; //default = 2, cuidado com margens muito grandes pois diminuem em excesso a área de impressão + $danfe2->printParameters($orientacao, $papel, $margSup, $margEsq); + + //NOTA: as margens inferior e direita são iguais à superior e esquerda, usadas como referencia + +``` + +## Modificadores + +São os métodos que modificam e/ou acrescentam comportamentos e informações ao pdf que será criado. + +Todos esses métodos são opcionais caso queira alterar o comportamento padrão da Danfe. + +```php + /** + * Define a font padrão a ser usada + * @param string $font + * @return void + */ + $font = 'times'; //opções times é a fonte obrigatória segundo a SEFAZ !! mas existe escolha para arial ou helvetica (ambas são iguais) + $danfe2->setDefaultFont($font); //default times exigido pelas SEFAZ + + /** + * Exibe ou não, os textos referentas as tag obsItem/obsCont e obsItem/obsFisco + * @param bool $val + * @return void + */ + $danfe2->exibirObservacoesNFe(false); //default true + + /** + * Exibe ou não, textos referentes a fatura caso não existam duplicatas e exista fatura + * @param bool $val + * @return void + */ + $danfe2->exibirFaturaNFe(false); //default true + + /** + * Exibe ou não, o email do destinatário no bloco infCpl, caso seja informado o email + * @param bool $val + * @return void + */ + $danfe2->exibirEmailDestinatarioNFe(false); //default true + + /** + * Exibe ou não, os dados de rastreamento dos ??????medicamentos em cada item, se existirem + * @param bool $val + * @return void + */ + $danfe2->exibirRastroItem(false); //default true + + /** + * Exibe ou não, os dados do pedido do destinatário em cada item, se existirem + * @param bool $val + * @return void + */ + $danfe2->exibirPedidoItem(false); //default true + + /** + * Exibe ou não, os dados de unidade tributável de cada item onde a unidade tributável for diferente da unidade comercial + * @param bool $val + * @return void + */ + $danfe2->exibirDadosTributaveisItem(false); //default true + + /** + * Exibe ou não, informações de impostos adicionais como FCP na descrição de cada item, se houverem + * @param bool $val + * @return void + */ + $danfe2->exibirImpostosAdicionaisItem(false); //default true + + /** + * Exibe ou não, o numero do item junto com o codigo de cada item + * @param bool $val + * @return void + */ + $danfe2->exibirNumeroItem(false); //default true + + + + + +``` + +## Elementos Adicionais + +São métodos que incluem informações ao DANFE. + +```php + + /** + * Exibe ou não, os dados do integrador e a mensagem "Powered by NFePHP®" + * @param string $message + * @param bool $powered + * @return void + */ + $message = 'WEBNFe Sistemas - http://www.webnfe.com.br'; //dados do integrador no rodapé da pagina + $powered = false; //exibe ou não o texto "Powered by NFePHP®" no rodapé da página + $danfe->creditsIntegratorFooter($message, $powered); + + /** + * Estabelece o logo e sua posição ou use o render para passar a imagem usando posição default + * Este método não necessita ser invocado apenas para inserir a logo sem alterar sua posição + * apenas use esse método caso deseja alterar a posição da logomarca + * Dê preferencia ao método render() para inserir a logo, nos padrões default + * @param string $logo + * @param string $logoAlign + * @param bool $mode_bw se true converte a imagem em branco e preto + * @return void + */ + //as imagens devem ser JPEG ou PNG obrigatóriamente e com um tamanho reazoável, evite imagens muito grandes ou com elevada resolução + $logo = 'path da imagem'; //usar um caminho à imagem ou 'data://text/plain;base64,'. {string da imagem em base64} + //logo = 'data://text/plain;base64,'. base64_encode(file_get_contents(__DIR__ . '/tulipas.png')); + $logoAlign = 'C'; //default C-centro, opções L-Left ou R-Right + $mode_bw = false; //default false, converte a imagem para preto e branco + $danfe2->logoParameters($logo, $logoAlign, $mode_bw); + + + $danfe2->setCancelFlag(true): //default false + +``` + +## Finalizadores + +```php + /** + * Renderizador, executa a montagem do PDF e retorna o pdf como string + * @param string $logo + * @return string + */ + $pdf = $danfe2->render($logo); + + + +``` + +## Exemplo + +```php + + +try { + + //dados + $xml = file_get_contents(__DI__.'/arquivo_xml_nfe_modelo_55.xml'); + $logo = 'data://text/plain;base64,'. base64_encode(file_get_contents(__DIR__ . '/tulipas.png')); + + //inicialização + $danfe2 = new Danfe2($xml); + + //Parametrização + //$orientacao = ''; //se deixar em branco será usada a orientação indicada no XML, default = '', opções 'P' ou 'L', qualquer outra opção será ignorada + //$papel = 'A4'; //default = 'A4', opção 'LEGAL' => recomenda-se usar sempre A4, qualquer outra opção será ignorada + //$margSup = 2; //default = 2, cuidado com margens muito grandes pois diminuem em excesso a área de impressão + //$margEsq = 2; //default = 2, cuidado com margens muito grandes pois diminuem em excesso a área de impressão + //$danfe2->printParameters($orientacao, $papel, $margSup, $margEsq); + + //modificadores + $danfe2->exibirFatura(false); //default true + $danfe2->exibirRastro(false); //default true + $danfe2->exibirPedido(false); //default true + $danfe2->exibirUnidadeTributavel(false); //default true + $danfe2->exibirImpostosAdicionais(false); //default true + $danfe2->exibirEmail(false); //default true + $danfe2->exibirNumeroItem(false); //default true + $danfe2->exibirObservacoes(false); //default true + + //adicionais + $danfe->creditsIntegratorFooter('WEBNFe Sistemas - http://www.webenf.com.br', true); + $danfe->logoParameters($logo, 'L', true); + + //finalização + $pdf = $danfe->render(); + //o pdf porde ser exibido como view no browser + //salvo em arquivo + //ou setado para download forçado no browser + //ou ainda gravado na base de dados + header('Content-Type: application/pdf'); + echo $pdf; + +} catch (\Exception $e) { + echo "Ocorreu um erro durante o processamento: " . $e->getMessage(); +} +``` diff --git a/src/Common/NfeStd.php b/src/Common/NfeStd.php new file mode 100644 index 00000000..c5576fce --- /dev/null +++ b/src/Common/NfeStd.php @@ -0,0 +1,91 @@ +preserveWhiteSpace = false; + $dom->formatOutput = false; + try { + $dom->loadXML($xml); + } catch (\Exception $e) { + return null; + } + foreach ($rootTagList as $key) { + $node = !empty($dom->getElementsByTagName($key)->item(0)) + ? $dom->getElementsByTagName($key)->item(0) + : ''; + if (!empty($node)) { + return $dom->saveXML($node); + } + } + return null; + } + + /** + * Return QRCODE and urlChave from XML + * @return array + */ + private static function getQRCode($xml): array + { + $resp = [ + 'qrCode' => '', + 'urlChave' => '' + ]; + $dom = new \DOMDocument('1.0', 'UTF-8'); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = false; + $dom->loadXML($xml); + $node = $dom->getElementsByTagName('infNFeSupl')->item(0); + if (!empty($node)) { + $resp = [ + 'qrCode' => $node->getElementsByTagName('qrCode')->item(0)->nodeValue, + 'urlChave' => $node->getElementsByTagName('urlChave')->item(0)->nodeValue + ]; + } + return $resp; + } + +} diff --git a/src/Legacy/FPDF/Fpdf.php b/src/Legacy/FPDF/Fpdf.php index 774de079..b647dafc 100644 --- a/src/Legacy/FPDF/Fpdf.php +++ b/src/Legacy/FPDF/Fpdf.php @@ -8,7 +8,7 @@ class Fpdf { const FPDF_VERSION = '1.6'; const FPDF_FONTPATH = '/font/'; - + public $page; //current page number public $n; //current object number public $offsets; //array of object offsets @@ -67,7 +67,7 @@ class Fpdf public $creator; //creator public $aliasNbPages; //alias for total number of pages public $pdfVersion; //PDF version number - + public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4') { //Some checks @@ -114,13 +114,13 @@ public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4') 'zapfdingbats'=>'ZapfDingbats' ]; //Scale factor - if ($unit == 'pt') { + if ($unit === 'pt') { $this->k = 1; - } elseif ($unit == 'mm') { + } elseif ($unit === 'mm') { $this->k = 72/25.4; - } elseif ($unit == 'cm') { + } elseif ($unit === 'cm') { $this->k = 72/2.54; - } elseif ($unit == 'in') { + } elseif ($unit === 'in') { $this->k = 72; } else { $this->error('Incorrect unit: '.$unit); @@ -170,7 +170,7 @@ public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4') //Set default PDF version number $this->pdfVersion='1.3'; } - + public function setMargins($left, $top, $right = null) { //Set left, top and right margins @@ -181,7 +181,7 @@ public function setMargins($left, $top, $right = null) } $this->rMargin=$right; } - + public function setLeftMargin($margin) { //Set left margin @@ -190,19 +190,19 @@ public function setLeftMargin($margin) $this->x = $margin; } } - + public function setTopMargin($margin) { //Set top margin $this->tMargin = $margin; } - + public function setRightMargin($margin) { //Set right margin $this->rMargin = $margin; } - + public function setAutoPageBreak($auto, $margin = 0) { //Set auto page break mode and triggering margin @@ -210,22 +210,22 @@ public function setAutoPageBreak($auto, $margin = 0) $this->bMargin = $margin; $this->pageBreakTrigger = $this->h-$margin; } - + public function setDisplayMode($zoom, $layout = 'continuous') { //Set display mode in viewer - if ($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) { + if ($zoom==='fullpage' || $zoom==='fullwidth' || $zoom==='real' || $zoom==='default' || !is_string($zoom)) { $this->zoomMode = $zoom; } else { $this->error('Incorrect zoom display mode: '.$zoom); } - if ($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') { + if ($layout==='single' || $layout==='continuous' || $layout==='two' || $layout==='default') { $this->layoutMode = $layout; } else { $this->error('Incorrect layout display mode: '.$layout); } } - + public function setCompression($compress) { //Set page compression @@ -235,7 +235,7 @@ public function setCompression($compress) $this->compress = false; } } - + public function setTitle($title, $isUTF8 = false) { //Title of document @@ -244,7 +244,7 @@ public function setTitle($title, $isUTF8 = false) } $this->title = $title; } - + public function setSubject($subject, $isUTF8 = false) { //Subject of document @@ -253,7 +253,7 @@ public function setSubject($subject, $isUTF8 = false) } $this->subject = $subject; } - + public function setAuthor($author, $isUTF8 = false) { //Author of document @@ -262,7 +262,7 @@ public function setAuthor($author, $isUTF8 = false) } $this->author=$author; } - + public function setKeywords($keywords, $isUTF8 = false) { //Keywords of document @@ -271,7 +271,7 @@ public function setKeywords($keywords, $isUTF8 = false) } $this->keywords = $keywords; } - + public function setCreator($creator, $isUTF8 = false) { //Creator of document @@ -280,23 +280,23 @@ public function setCreator($creator, $isUTF8 = false) } $this->creator = $creator; } - + public function aliasNbPages($alias = '{nb}') { //Define an alias for total number of pages $this->aliasNbPages=$alias; } - + public function error($msg) { throw new Exception($msg); } - + public function open() { $this->state = 1; } - + public function close() { //Terminate document @@ -315,7 +315,7 @@ public function close() //Close document $this->endDoc(); } - + public function addPage($orientation = '', $format = '') { //Start a new page @@ -351,11 +351,11 @@ public function addPage($orientation = '', $format = '') } //Set colors $this->drawColor = $dc; - if ($dc!='0 G') { + if ($dc!=='0 G') { $this->out($dc); } $this->fillColor = $fc; - if ($fc != '0 g') { + if ($fc !== '0 g') { $this->out($fc); } $this->textColor = $tc; @@ -385,23 +385,23 @@ public function addPage($orientation = '', $format = '') $this->textColor = $tc; $this->colorFlag = $cf; } - + public function header() { //To be implemented in your own inherited class } - + public function footer() { //To be implemented in your own inherited class } - + public function pageNo() { //Get current page number return $this->page; } - + public function setDrawColor($r, $g = null, $b = null) { //Set color for all stroking operations @@ -414,7 +414,7 @@ public function setDrawColor($r, $g = null, $b = null) $this->out($this->drawColor); } } - + public function setFillColor($r, $g = null, $b = null) { //Set color for all filling operations @@ -428,7 +428,7 @@ public function setFillColor($r, $g = null, $b = null) $this->out($this->fillColor); } } - + public function settextColor($r, $g = null, $b = null) { //Set color for text @@ -439,7 +439,7 @@ public function settextColor($r, $g = null, $b = null) } $this->colorFlag = ($this->fillColor != $this->textColor); } - + public function getStringWidth($s) { //Get width of a string in the current font @@ -452,7 +452,7 @@ public function getStringWidth($s) } return $w*$this->fontSize/1000; } - + public function setLineWidth($width) { //Set line width @@ -461,7 +461,7 @@ public function setLineWidth($width) $this->out(sprintf('%.2F w', $width*$this->k)); } } - + public function line($x1, $y1, $x2, $y2) { //Draw a line @@ -475,7 +475,7 @@ public function line($x1, $y1, $x2, $y2) ) ); } - + public function rect($x, $y, $w, $h, $style = '') { //Draw a rectangle @@ -497,7 +497,7 @@ public function rect($x, $y, $w, $h, $style = '') ) ); } - + public function addFont($family, $style = '', $file = '') { //Add a TrueType or Type1 font @@ -556,7 +556,7 @@ public function addFont($family, $style = '', $file = '') } } } - + public function setFont($family, $style = '', $size = 0) { //Select a font; size given in points @@ -621,7 +621,7 @@ public function setFont($family, $style = '', $size = 0) $this->out(sprintf('BT /F%d %.2F Tf ET', $this->currentFont['i'], $this->fontSizePt)); } } - + public function setFontSize($size) { //Set font size in points @@ -634,7 +634,7 @@ public function setFontSize($size) $this->out(sprintf('BT /F%d %.2F Tf ET', $this->currentFont['i'], $this->fontSizePt)); } } - + public function addlink() { //Create a new internal link @@ -642,7 +642,7 @@ public function addlink() $this->links[$n] = [0, 0]; return $n; } - + public function setlink($link, $y = 0, $page = -1) { //Set destination of internal link @@ -654,7 +654,7 @@ public function setlink($link, $y = 0, $page = -1) } $this->links[$link] = [$page, $y]; } - + public function link($x, $y, $w, $h, $link) { //Put a link on the page @@ -666,7 +666,7 @@ public function link($x, $y, $w, $h, $link) $link ]; } - + public function text($x, $y, $txt) { //Output a string @@ -679,13 +679,13 @@ public function text($x, $y, $txt) } $this->out($s); } - + public function acceptPageBreak() { //Accept automatic page break or not return $this->autoPageBreak; } - + public function cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '') { //Output a cell @@ -797,7 +797,7 @@ public function cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $ $this->x += $w; } } - + public function multicell($w, $h, $txt, $border = 0, $align = 'J', $fill = false) { //Output text with automatic or explicit line breaks @@ -903,8 +903,8 @@ public function multicell($w, $h, $txt, $border = 0, $align = 'J', $fill = false $this->cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill); $this->x = $this->lMargin; } - - + + public function write($h, $txt, $link = '') { //Output text in flowing mode @@ -979,7 +979,7 @@ public function write($h, $txt, $link = '') $this->cell($l/1000*$this->fontSize, $h, substr($s, $j), 0, 0, '', 0, $link); } } - + public function ln($h = null) { //Line feed; default value is last cell height @@ -990,7 +990,7 @@ public function ln($h = null) $this->y += $h; } } - + public function image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') { //Put an image on the page @@ -1059,15 +1059,15 @@ public function image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $ $this->link($x, $y, $w, $h, $link); } } - - + + public function getX() { //Get x position return $this->x; } - - + + public function setX($x) { //Set x position @@ -1077,15 +1077,15 @@ public function setX($x) $this->x = $this->w+$x; } } - - + + public function getY() { //Get y position return $this->y; } - - + + public function setY($y) { //Set y position and reset x @@ -1096,15 +1096,15 @@ public function setY($y) $this->y = $this->h+$y; } } - - + + public function setXY($x, $y) { //Set x and y positions $this->setY($y); $this->setX($x); } - + public function getPdf() { if ($this->state < 3) { @@ -1112,7 +1112,7 @@ public function getPdf() } return $this->buffer; } - + public function output($name = '', $dest = '') { //Output PDF to some destination @@ -1181,8 +1181,8 @@ public function output($name = '', $dest = '') } return ''; } - - + + protected function dochecks() { //Check availability of %F @@ -1194,8 +1194,8 @@ protected function dochecks() $this->error('mbstring overloading must be disabled'); } } - - + + protected function getpageformat($format) { $format=strtolower($format); @@ -1205,14 +1205,14 @@ protected function getpageformat($format) $a=$this->pageFormats[$format]; return [$a[0]/$this->k, $a[1]/$this->k]; } - - + + protected function getFontPath() { return __DIR__ . self::FPDF_FONTPATH; } - - + + protected function beginPage($orientation, $format) { $this->page++; @@ -1259,14 +1259,14 @@ protected function beginPage($orientation, $format) $this->PageSizes[$this->page] = [$this->wPt, $this->hPt]; } } - - + + protected function endPage() { $this->state = 1; } - - + + protected function escape($s) { //Escape special characters in strings @@ -1276,15 +1276,15 @@ protected function escape($s) $s = str_replace("\r", '\\r', $s); return $s; } - - + + protected function textString($s) { //Format a text string return '('.$this->escape($s).')'; } - - + + protected function utf8Toutf16($s) { //Convert UTF-8 to UTF-16BE with BOM @@ -1311,8 +1311,8 @@ protected function utf8Toutf16($s) } return $res; } - - + + protected function doUnderLine($x, $y, $txt) { //Underline text @@ -1327,8 +1327,8 @@ protected function doUnderLine($x, $y, $txt) -$ut/1000*$this->fontSizePt ); } - - + + protected function parseJPG($file) { //Extract info from a JPEG file @@ -1356,8 +1356,8 @@ protected function parseJPG($file) fclose($f); return ['w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data]; } - - + + protected function parsePNG($file) { //Extract info from a PNG file @@ -1458,8 +1458,8 @@ protected function parsePNG($file) 'data'=>$data ]; } - - + + protected function readstream($f, $n) { //Read n bytes from stream @@ -1477,16 +1477,16 @@ protected function readstream($f, $n) } return $res; } - - + + protected function readint($f) { //Read a 4-byte integer from stream $a = unpack('Ni', $this->readstream($f, 4)); return $a['i']; } - - + + protected function parseGIF($file) { //Extract info from a GIF file (via PNG conversion) @@ -1513,8 +1513,8 @@ protected function parseGIF($file) unlink($tmp); return $info; } - - + + protected function newObj() { //Begin a new object @@ -1522,16 +1522,16 @@ protected function newObj() $this->offsets[$this->n] = strlen($this->buffer); $this->out($this->n.' 0 obj'); } - - + + protected function putStream($s) { $this->out('stream'); $this->out($s); $this->out('endstream'); } - - + + protected function out($s) { //Add a line to the document @@ -1541,8 +1541,8 @@ protected function out($s) $this->buffer .= $s."\n"; } } - - + + protected function putPages() { $nb = $this->page; @@ -1608,8 +1608,8 @@ protected function putPages() $this->out('>>'); $this->out('endobj'); } - - + + protected function putFonts() { $nf = $this->n; @@ -1721,13 +1721,13 @@ protected function putFonts() } } } - - + + protected function putImages() { $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; reset($this->images); - + foreach ($this->images as $file => $info) { $this->newObj(); $this->images[$file]['n'] = $this->n; @@ -1771,14 +1771,14 @@ protected function putImages() } } } - + protected function putXobjectDict() { foreach ($this->images as $image) { $this->out('/I'.$image['i'].' '.$image['n'].' 0 R'); } } - + protected function putResourceDict() { $this->out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); @@ -1791,7 +1791,7 @@ protected function putResourceDict() $this->putXobjectDict(); $this->out('>>'); } - + protected function putResources() { $this->putFonts(); @@ -1804,7 +1804,7 @@ protected function putResources() $this->out('>>'); $this->out('endobj'); } - + protected function putInfo() { $this->out('/Producer '.$this->textString('FPDF '. self::FPDF_VERSION)); @@ -1825,7 +1825,7 @@ protected function putInfo() } $this->out('/CreationDate '.$this->textString('D:'.@date('YmdHis'))); } - + protected function putCatalog() { $this->out('/Type /Catalog'); @@ -1847,19 +1847,19 @@ protected function putCatalog() $this->out('/PageLayout /TwoColumnLeft'); } } - + protected function putHeader() { $this->out('%PDF-'.$this->pdfVersion); } - + protected function putTrailer() { $this->out('/Size '.($this->n+1)); $this->out('/Root '.$this->n.' 0 R'); $this->out('/Info '.($this->n-1).' 0 R'); } - + protected function endDoc() { $this->putHeader(); diff --git a/src/Legacy/Pdf.php b/src/Legacy/Pdf.php index e1ae8e0b..3237ff4d 100644 --- a/src/Legacy/Pdf.php +++ b/src/Legacy/Pdf.php @@ -169,7 +169,8 @@ public function code128($x, $y, $code, $w, $h) $Aguid=""; $Bguid=""; $Cguid=""; - for ($i=0; $i < strlen($code); $i++) { + $len = strlen($code); + for ($i=0; $i < $len; $i++) { $needle=substr($code, $i, 1); $Aguid .= ((strpos($this->aSet, $needle)===false) ? "N" : "O"); $Bguid .= ((strpos($this->bSet, $needle)===false) ? "N" : "O"); diff --git a/src/NFe/Traits/TraitCanhotoNfe.php b/src/NFe/Traits/TraitCanhotoNfe.php new file mode 100644 index 00000000..0fa5e552 --- /dev/null +++ b/src/NFe/Traits/TraitCanhotoNfe.php @@ -0,0 +1,157 @@ +orientacao}"; + $emitente = $this->std->emit->xNome; + $data = $this->data->format('d/m/Y H:i:s'); + $valor = number_format( + (float)$this->std->total->ICMSTot->vNF, + 2, + ',', + '.' + ); + $destinatario = $this->std->dest->xNome + . ' ' . $this->std->dest->enderDest->xLgr + . ', ' . $this->std->dest->enderDest->nro + . ' ' . $this->std->dest->enderDest->xBairro + . ' ' . $this->std->dest->enderDest->xMun + . '-' . $this->std->dest->enderDest->UF; + return $this->$cabecfunc($emitente, $this->numero, $this->serie, $data, $valor, $destinatario); + } + + /** + * Insere canhoto + * @param string $emitente + * @return int + */ + protected function canhotoP($emitente, $numero, $serie, $data, $valor, $destinatario): float + { + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => '']; + $aFontSmall = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $w = round($this->wPrint * 0.86, 0); //texto princippal + $w1 = $this->wPrint - $w; //dados da nfe + $w2 = round($this->wPrint * 0.17, 0); //data recebimento + $w3 = $this->wPrint - $w2 - $w1; //assinatura + $x = $this->margesq; + $y = $this->margsup; + $texto = "RECEBEMOS DE "; + $texto .= $emitente; + $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ABAIXO. EMISSÃO: "; + $texto .= $data; + $texto .= " NO VALOR TOTAL: R$ "; + $texto .= $valor . " "; + $texto .= "DESTINATÁRIO: "; + $texto .= $destinatario . ' bla sjksj skjs js js kjsl sj slksjlskjsslksjlsk slkjsls sjs lkjs kjslskjslkjslksjsk kjskj lskj lskj skjslkjs slkjslk slksj skjs lksjs lksj sklsj'; + $h = ceil($this->calculeHeight($texto, $w, $aFont)+1); + $h1 = 8; //altura da linha para escrever + $htot = $h + $h1 + 1; + //################## BORDAS E DIVISORIAS + //desenha caixa externa + $this->pdf->textBox($x, $y, $this->wPrint, $htot, '', $aFont, 'C', 'L', 1, '', false); + //linha separadora horizontal + $this->pdf->line($this->margesq, $y+$h, $this->margesq+$w, $y+$h+1); + //linha separadora vertical + $this->pdf->line($this->margesq+$w, $this->margsup, $this->margesq+$w, $htot+$this->margsup); + //linha separadora vertical inferior + $this->pdf->line($this->margesq+$w2, $this->margsup+$h, $this->margesq+$w2, $htot+$this->margsup); + //########### BLOCO TEXTO + //insere texto + $this->pdf->textBox($x, $y, $w-3, $h, $texto, $aFont, 'C', 'L', 0, '', false); + $x1 = $x + $w; + $texto = "NF-e"; + $aFont = ['font' => $this->fontePadrao, 'size' => 14, 'style' => 'B']; + $this->pdf->textBox($x1, $y, $w1, $htot, $texto, $aFont, 'T', 'C', 0, ''); + $texto = "Nº. " . $numero . " \n"; + $texto .= "Série $serie"; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x1, $y, $w1, $htot, $texto, $aFont, 'C', 'C', 0, ''); + + //################ BLOCO DATA / ASSINATURA + //DATA DE RECEBIMENTO + $texto = "DATA DE RECEBIMENTO"; + $y += $h; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h1,$texto, $aFont, 'T', 'L', 0, ''); + //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR + $x += $w2; + $w3 = $w - $w2; + $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"; + $this->pdf->textBox($x, $y, $w3, $h1, $texto, $aFont, 'T', 'L', 0, ''); + $y = $htot+$this->margsup+1; + $this->pdf->dashedHLine($this->margesq, $y, $this->wPrint, 0.1, 80); + return $htot+2; + } + + protected function canhotoL($emitente, $numero, $serie, $data, $valor, $destinatario): float + { + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => '']; + $aFontSmall = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $h = round($this->hPrint * 0.86, 0); //texto princippal + $h1 = $this->hPrint - $h - $this->margsup; //dados da nfe + $h2 = round($this->hPrint * 0.17, 0); //data recebimento + $h3 = $this->wPrint - $h2 - $h1; //assinatura + $x = $this->margesq; + $y = $this->margsup; + $texto = "RECEBEMOS DE "; + $texto .= $emitente; + $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ABAIXO. EMISSÃO: "; + $texto .= $data; + $texto .= " NO VALOR TOTAL: R$ "; + $texto .= $valor . " "; + $texto .= "DESTINATÁRIO: "; + $texto .= $destinatario; + $w = ceil($this->calculeHeight($texto, $h, $aFont)+1); + $w1 = 8; //altura da linha para escrever + //$wtot = $w + $w1 + 1; + //################## BORDAS E DIVISORIAS + //como está rotacionado as coordenadas y iniciam de baixo para cima + $this->pdf->textBox90($this->margesq, $this->hPrint, $this->hPrint-$this->margsup, $w+$w1, '', $aFont, 'C', 'L', 1, '', false); + //linha separadora vertical + $this->pdf->line($this->margesq+$w, $this->hPrint, $this->margesq+$w, $this->hPrint-$h); + //linha separadora horizontal + $this->pdf->line($this->margesq, $this->hPrint-$h, $this->margesq+$w+$w1, $this->hPrint-$h); + //linha separadora horizontal inferior + //$this->margesq+$w, $this->hPrint-$h2-$this->margsup, $h-$this->margsup, $w + $this->pdf->line($this->margesq+$w, $this->hPrint-$h2-$this->margsup, $this->margesq+$w+$w1, $this->hPrint-$h2-$this->margsup); + //########### BLOCO TEXTO + //insere texto + $this->pdf->textBox90($this->margesq, $this->hPrint, $h-$this->margsup, $w, $texto, $aFont, 'C', 'L', 0, '', false); + $texto = "NF-e"; + $aFont = ['font' => $this->fontePadrao, 'size' => 14, 'style' => 'B']; + $this->pdf->textBox90($this->margesq, $this->hPrint-$h, $h1, 7, $texto, $aFont, 'T', 'C', 0, ''); + $texto = "Nº. " . $numero . " \n"; + $texto .= "Série $serie"; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox90($this->margesq+4.5, $this->hPrint-$h, $h1, $w1, $texto, $aFont, 'C', 'C', 0, ''); + //################ BLOCO DATA / ASSINATURA + //DATA DE RECEBIMENTO + $texto = "DATA DE RECEBIMENTO"; + $y += $h; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox90($this->margesq+$w, $this->hPrint, $h-$this->margsup, $w,$texto, $aFont, 'T', 'L', 0, ''); + + //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR + $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"; + $this->pdf->textBox90($this->margesq+$w, $this->hPrint-$h2-$this->margsup, $h-$this->margsup, $w, $texto, $aFont, 'T', 'L', 0, ''); + /* + $y = $htot+$this->margsup+1; + $this->pdf->dashedHLine($this->margesq, $y, $this->wPrint, 0.1, 80); + return $htot+2; + */ + //$this->pdf->line($this->margesq+$w, $this->hPrint, $this->margesq+$w, $this->hPrint-$h); + //$this->pdf->dashedHLine($this->margesq+$w, $y, $this->wPrint, 0.1, 80); + $this->pdf->dashedVLine($this->margesq+$w+$w1+1, $this->hPrint, 0.1, $this->margsup, 80); + return 2; + + } +} diff --git a/src/NFe/Traits/TraitDadosAdicionaisNfe.php b/src/NFe/Traits/TraitDadosAdicionaisNfe.php new file mode 100644 index 00000000..4317e7e3 --- /dev/null +++ b/src/NFe/Traits/TraitDadosAdicionaisNfe.php @@ -0,0 +1,117 @@ +orientacao}"; + return $this->$dados($infCpl, $infAdFisco, $heigth); + } + + public function dadosAdicionaisP(string $infCpl = '', string $infAdFisco = '', float $heigth = null): object + { + if (empty($heigth)) { + $heigth = 24; + } + $h = $heigth; + $y = $this->maxH - (7 + $h); + $x = $this->margesq; + $wAdic = round($this->wPrint * 0.66, 0); + $wFisco = round($this->wPrint - $wAdic, 0); + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y+3, $this->wPrint, $heigth, '', $aFont, 'T', 'L', 1, ''); + //linha vertical + $this->pdf->line($x+$wAdic, $y+3, $x+$wAdic, $y+$heigth+3); + + //################################################################################## + //DADOS ADICIONAIS + $texto = "DADOS ADICIONAIS"; + $w = $this->wPrint; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, ''); + + //INFORMAÇÕES COMPLEMENTARES + $texto = "INFORMAÇÕES COMPLEMENTARES"; + $y += 3; + $w = $wAdic; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); + //o texto com os dados adicionais foi obtido na função montaDANFE + //e carregado em uma propriedade privada da classe + $y += 1; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $info = $infCpl; + $info = preg_replace('/(?:\s\s+)/', ' ', $info); + $info = str_replace(';', "\n", $info); + $resp = $this->limitLines(9, $info, $w, $aFont); + $complemento = ""; + $infCpl = ''; + if ($resp->pos < $resp->len) { + $infCpl = substr($info, $resp->pos); + $complemento = " CONTINUA ..."; + } + $texto = trim($resp->string) . $complemento; + $this->pdf->textBox($x, $y + 2, $w - 2, $h, $texto, $aFont, 'T', 'L', 0, '', false); + //RESERVADO AO FISCO + $texto = "RESERVADO AO FISCO"; + $x += $w; + $y -= 1; + $w = $this->wPrint - $w; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); + $resp = $this->limitLines(9, $infAdFisco, $w, $aFont); + $complemento = ""; + $infAdFisco = ''; + if ($resp->pos < $resp->len && !empty($info)) { + $infAdFisco = substr($info, $resp->pos); + $complemento = " CONTINUA ..."; + } + $texto = $resp->string . $complemento; + $y += 2; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => '']; + $this->pdf->textBox($x, $y, $w - 2, $h, $texto, $aFont, 'T', 'L', 0, '', false); + + return (object) [ + 'infCpl' => $infCpl, + 'infAdFisco' => $infAdFisco, + 'heigth' => $h + 8 + ]; + } + + public function dadosAdicionaisL(string $infCpl, string $infAdFisco, float $heigth = null): object + { + + } + + public function limitLines(int $max, string $texto, float $width, array $font): object + { + if (empty($texto)) { + return (object) ['string' => '', 'pos' => 0, 'len' => 0]; + } + $string = trim($texto); + $numLin = $this->pdf->getNumLines($texto, $width, $font); + $len = strlen($string); + $pos = $len; + if ($numLin > $max) { + while (true) { + $numLin = $this->pdf->getNumLines($string, $width, $font); + if ($numLin > $max) { + $posspc = strrpos($string, ' '); + $poslf = strrpos($string, "\n"); + $pos = $posspc < $poslf ? $poslf : $posspc; + $string = substr($string, 0, $pos); + } else { + $posspc = strrpos($string, ' '); + $poslf = strrpos($string, "\n"); + $pos = $posspc < $poslf ? $poslf : $posspc; + $string = substr($string, 0, $pos); + break; + } + } + } + return (object) ['string' => $string, 'pos' => $pos, 'len' => $len]; + } + +} diff --git a/src/NFe/Traits/TraitDadosAdicionaisNfeOutras.php b/src/NFe/Traits/TraitDadosAdicionaisNfeOutras.php new file mode 100644 index 00000000..296bf999 --- /dev/null +++ b/src/NFe/Traits/TraitDadosAdicionaisNfeOutras.php @@ -0,0 +1,25 @@ +orientacao}"; + return $this->$dados($infCpl, $infAdFisco); + } + + public function dadosAdicionaisOutrasP(string $infCpl = '', string $infAdFisco = ''): float + { + return 0; + } + + public function dadosAdicionaisOutrasL(string $infCpl = '', string $infAdFisco = ''): float + { + return 0; + } +} diff --git a/src/NFe/Traits/TraitDestinatarioNfe.php b/src/NFe/Traits/TraitDestinatarioNfe.php new file mode 100644 index 00000000..3a595ac7 --- /dev/null +++ b/src/NFe/Traits/TraitDestinatarioNfe.php @@ -0,0 +1,169 @@ +orientacao}"; + return $this->$dest($y); + } + + protected function destinatarioP(float $y): float + { + $x = $this->margesq; + $oldX = $x; + //#################################################################################### + //DESTINATÁRIO / REMETENTE + $w = round($this->wPrint * 0.61, 0); //nome + $w1 = round($this->wPrint * 0.23, 0); //cnpj + $w2 = $this->wPrint - $w - $w1; //datas horas + $w3 = round($this->wPrint * 0.47, 0); //endereço + $w4 = round($this->wPrint * 0.21, 0); //bairro + $w5 = $this->wPrint - $w3 - $w4 - $w2; //CEP + $wuf = 8; + $w6 = $this->wPrint - $w3 - $wuf - $w2 - $w5; + $w7 = $this->wPrint - $w3 - $wuf - $w2 - $w6; + $h = 7; + $htot = 21; + $texto = 'DESTINATÁRIO / REMETENTE'; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $this->wPrint, $h, $texto, $aFont, 'T', 'L', 0, ''); + //borda do campo destinatário/remetente + $this->pdf->textBox($x, $y+3, $this->wPrint, $htot, '', $aFont, 'T', 'L', 1, ''); + //linhas horizontais + $this->pdf->line($x, $y+10, $this->wPrint+$this->margesq, $y+10); + $this->pdf->line($x, $y+17, $this->wPrint+$this->margesq, $y+17); + //linhas verticais + $this->pdf->line($x+$w, $y+3, $x+$w, $y+10); //nome | cnpj + $this->pdf->line($x+$w+$w1, $y+3, $x+$w+$w1, $y+$htot+3); //nome | cnpj + $this->pdf->line($x+$w3, $y+10, $x+$w3, $y+24); //endereco | bairro + $this->pdf->line($x+$w3+$w4, $y+10, $x+$w3+$w4, $y+24); //bairro | cep + $this->pdf->line($x+$w3+8, $y+17, $x+$w3+8, $y+24); //municipio | uf + + //NOME / RAZÃO SOCIAL w = 61 % + $y += 3; + $texto = 'NOME / RAZÃO SOCIAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->xNome; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //CNPJ / CPF + $x += $w; + $texto = 'CNPJ / CPF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //Pegando valor do CPF/CNPJ + if (!empty($this->std->dest->CNPJ ?? null)) { + $texto = $this->formatField( + $this->std->dest->CNPJ, + "###.###.###/####-##" + ); + } else { + $texto = !empty($this->std->dest->CPF ?? null) + ? $this->formatField( + $this->std->dest->CPF, + "###.###.###-##" + ) + : ''; + } + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w1, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //DATA DA EMISSÃO + $x += $w1; + $texto = 'DATA DA EMISSÃO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->data->format('d/m/Y'); + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w2, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //ENDEREÇO + $y += $h; + $x = $this->margesq; + $texto = 'ENDEREÇO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->enderDest->xLgr; + $texto .= ', ' . $this->std->dest->enderDest->nro; + $texto .= ' ' . ($this->std->dest->enderDest->xCpl ?? ''); + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w3, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //BAIRRO / DISTRITO + $x += $w3; + $texto = 'BAIRRO / DISTRITO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->enderDest->xBairro ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w4, $h, $texto, $aFont, 'T', 'C', 0, '',true); + //CEP + $x += $w4; + $texto = 'CEP'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->enderDest->CEP ?? ''; + $texto = $this->formatField($texto, "#####-###"); + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w5, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //DATA DA SAÍDA + $x += $w5; + $texto = 'DATA DA SAÍDA/ENTRADA'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = !empty($this->datasaida) ? $this->datasaida->format('d/m/Y') : ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w2, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //MUNICÍPIO + $y += $h; + $x = $this->margesq; + $texto = 'MUNICÍPIO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->enderDest->xMun; + if (strtoupper(trim($texto)) === "EXTERIOR" && !empty($this->std->dest->enderDest->xPais)) { + $texto .= " - " . $this->std->dest->enderDest->xPais; + } + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w3, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //UF + $x += $w3; + $texto = 'UF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $wuf, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->enderDest->UF; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $wuf, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //FONE / FAX + $x += $wuf; + $texto = 'FONE / FAX'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->enderDest->fone ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //INSCRIÇÃO ESTADUAL + $x += $w6; + $texto = 'INSCRIÇÃO ESTADUAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->dest->enderDest->IE ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w7, $h, $texto, $aFont, 'T', 'R', 0, '', true); + //HORA DA SAÍDA + $x += $w7; + $texto = 'HORA DA SAÍDA/ENTRADA'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = !empty($this->datasaida) ? $this->datasaida->format('H:i:s') : ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w2, $h, $texto, $aFont, 'T', 'C', 0, '', true); + return 24; + } + + protected function destinatarioL(float $y): float + { + return 24; + } +} diff --git a/src/NFe/Traits/TraitDuplicatasNfe.php b/src/NFe/Traits/TraitDuplicatasNfe.php new file mode 100644 index 00000000..fb3ec0be --- /dev/null +++ b/src/NFe/Traits/TraitDuplicatasNfe.php @@ -0,0 +1,215 @@ +orientacao}"; + return $this->$dup($y, $dups, $total); + } + + protected function duplicatasP(float $y, array $dups, int $total = 0): float + { + $x = $this->margesq; + $linha = 1; + $oldx = $x; + if (empty($dups) && $this->exibirFatura && !empty($this->std->cobr->fat)) { + //exibir dados de pagamento no bloco + $texto = $this->getTextoFatura(); + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $lines = $this->pdf->getNumLines($texto, $this->wPrint, $aFont); + $tit = "FATURA / DUPLICATA"; + $w = $this->wPrint; + $h = $lines * 4; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, 5, $tit, $aFont, 'T', 'L', 0, ''); + $this->pdf->textBox($x, $y+3, $w, $h, '', $aFont, 'T', 'L', 1, ''); + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+3, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); + return $h+3; + } + //caso não tenha dados de + if (empty($dups) && !$this->exibirFatura) { + return 0; + } + + + //##################################################################### + $w = $this->wPrint / 10; + $h = 8; + //FATURA / DUPLICATA + $texto = "FATURA / DUPLICATA"; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); + $yx = $y+3; + //define o numero de blocos para inserir das duplicatas + $linhas = ceil(count($dups)/10); + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + for($l=1; $l<=$linhas; $l++) { + //insere a borda do bloco + $this->pdf->textBox($x, $yx, $this->wPrint, $h, '', $aFont, 'T', 'L', 1, ''); + $xl = $x; + for($k=1; $k<=9; $k++) { + $xl += $w; + $this->pdf->line($xl, $yx, $xl, $yx+$h); + } + $yx += $h; + } + $y += 3; + $slice = array_chunk($dups, 10); + $hfim = 0; + foreach ($slice as $key => $ds) { + $hfim += $h; + foreach ($ds as $d) { + $nDup = $d->nDup; + $dDup = \DateTime::createFromFormat('Y-m-d', $d->dVenc)->format('d/m/Y'); + $vDup = 'R$ ' . number_format($d->vDup, 2, ',', '.'); + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 0, ''); + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, ''); + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, ''); + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, ''); + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, ''); + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x + 5.4, $y, $w - 5.4, $h, $vDup, $aFont, 'B', 'R', 0, ''); + $x += $w; + } + if ($key == count($slice) - 1 && $total > count($dups)) { + //tem mais duplicatas do que o limite de 20 + //incluir uma mensagem + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $h, 'EXISTEM MAIS DUPLICATAS NO XML', $aFont, 'C', 'C', 1, '', false); + } + $x = $this->margesq; + $y += 8; + } + return $hfim + 3; + } + + protected function duplicatasL(float $y, array $dups, int $total = 1): float + { + return 0; + } + + protected function getTextoFatura() + { + $formaPag = [ + 0 => 'Pagamento à vista', + 1 => 'Pagamento a prazo', + 2 => 'Outros' + ]; + $tipoPag = [ + '01' => 'Dinheiro', + '02' => 'Cheque', + '03' => 'Cartão de Crédito', + '04' => 'Cartão de Débito', + '05' => 'Crédito Loja', + '10' => 'Vale Alimentação', + '11' => 'Vale Refeição', + '12' => 'Vale Presente', + '13' => 'Vale Combustível', + '15' => 'Boleto Bancário', + '90' => 'Sem Pagamento', + '99' => 'Outro', + ]; + $bandeira = [ + '01' => 'Visa', + '02' => 'Mastercard', + '03' => 'American Express', + '04' => 'Sorocred', + '05' => 'Diners Club', + '06' => 'Elo', + '07' => 'Hipercard', + '08' => 'Aura', + '09' => 'Cabal', + '99' => 'Outros', + ]; + $fat = $this->std->cobr->fat ?? null; + $pag = $this->std->pag ?? null; + $texto = ''; + $textoFat = ''; + $itens = []; + $troco = null; + $indPag = $this->std->ide->indPag ?? null; + if (isset($indPag)) { + $textoFat = $formaPag[$indPag] . "\n"; + } + if (isset($fat)) { + $nFat = "Número Fatura: {$fat->nFat}"; + $vOrig = ", Valor Original: R$ " . number_format($fat->vOrig, 2, ',', '.'); + $vDesc = ", Valor Desconto: R$ " . number_format($fat->vDesc, 2, ',', '.'); + $vLiq = ", Valor Líquido: R$ " . number_format($fat->vLiq, 2, ',', '.'); + $textoFat .= $nFat . ' ' . $vOrig . ' ' . $vDesc . ' ' . $vLiq . "\n"; + } + if (isset($pag)) { + $i = 0; + if (is_array($pag->detPag)) { + foreach ($pag->detPag as $dp) { + if (isset($dp->indPag)) { + $itens[$i]['forma'] = $formaPag[$dp->indPag]; + } + $itens[$i]['tipo'] = $tipoPag[$dp->tPag]; + if ((string)$dp->tPag === '99') { + $itens[$i]['tipo'] = $tipoPag[$dp->tPag] . ', ' . $dp->xPag; + } + $itens[$i]['valor'] = 'R$ ' . number_format($dp->vPag, 2, ',', '.'); + if (!empty($dp->card)) { + if (!empty($dp->card->tBand)) { + $itens[$i]['bandeira'] = $bandeira[$dp->card->tBand]; + } + if (!empty($dp->card->cAut)) { + $itens[$i]['autenticacao'] = $dp->card->cAut; + } + } + $i++; + } + } else { + $dp = $pag->detPag; + if (isset($dp->indPag)) { + $textoFat = $formaPag[$dp->indPag] . "\n" . $textoFat; + } + $itens[$i]['tipo'] = $tipoPag[$dp->tPag]; + if ((string)$dp->tPag === '99') { + $itens[0]['tipo'] = $tipoPag[$dp->tPag] . ', ' . $dp->xPag; + } + $itens[$i]['valor'] = 'R$ ' . number_format($dp->vPag, 2, ',', '.'); + if (!empty($dp->card)) { + if (!empty($dp->card->tBand)) { + $itens[0]['bandeira'] = $bandeira[$dp->card->tBand]; + } + if (!empty($dp->card->cAut)) { + $itens[0]['autenticacao'] = $dp->card->cAut; + } + } + } + $troco = !empty($pag->troco) ? 'R$ ' . number_format($pag->troco, 2, ',', '.') : null; + } + if (count($itens) == 1) { + //tem um unico conjunto de detPag + $texto = $textoFat; + $texto .= $itens[0]['tipo']; + $texto .= !empty($itens[0]['bandeira']) ? $itens[0]['bandeira'] : ''; + $texto .= !empty($itens[0]['autenticacao']) ? $itens[0]['autenticacao'] : ''; + } else { + foreach($itens as $item) { + $std = (object) $item; + $texto = $textoFat; + $texto .= !empty($std->forma) ? $std->forma . ', ' : ''; + $texto .= $std->tipo . ' - Valor: ' . $std->valor; + $texto .= !empty($std->bandeira) ? $std->bandeira : ''; + $texto .= !empty($std->autenticacao) ? ' - aut: '. $std->autenticacao : ''; + $texto .= "\n"; + } + } + if (!empty($troco)) { + $texto .= ' Troco: ' . $troco; + } + return $texto; + } +} diff --git a/src/NFe/Traits/TraitHeaderNfe.php b/src/NFe/Traits/TraitHeaderNfe.php new file mode 100644 index 00000000..5105a61a --- /dev/null +++ b/src/NFe/Traits/TraitHeaderNfe.php @@ -0,0 +1,316 @@ +orientacao}"; + return $this->$head($y, $pagina, $totalPaginas); + } + + protected function headerP(float $y, $pagina = 1, $totalPaginas = 1): float + { + $x = $this->margesq; + $w = round($this->wPrint * 0.40, 0); + $w1 = round($this->wPrint * 0.17, 0); //35; + $w2 = $this->wPrint - ($w + $w1); + $w3 = round($this->wPrint * 0.250, 0); //ultima linha 4 divisorias + $h = 32; + $h1 = 7; + //desenha caixa principal + $this->pdf->textBox($this->margesq, $y, $this->wPrint, $h+2*$h1); + //linha divisória vertical + $this->pdf->line($this->margesq+$w, $y, $this->margesq+$w, $y+$h); + //linha divisória vertical + $this->pdf->line($this->margesq+$w+$w1, $y, $this->margesq+$w+$w1, $y+$h+$h1); + //linha divisoria horizontal + $this->pdf->line($this->margesq, $y+$h, $this->wPrint+$this->margesq, $y+$h); + //linha divisória vertical + $this->pdf->line($this->margesq+$w, $y+$h, $this->margesq+$w, $y+$h); + //#################################################################################### + //coluna esquerda identificação do emitente + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => 'I']; + $texto = 'IDENTIFICAÇÃO DO EMITENTE'; + $this->pdf->textBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '', true); + //estabelecer o alinhamento + //pode ser left L, center C, right R, full logo L + //se for left separar 1/3 da largura para o tamanho da imagem + //os outros 2/3 serão usados para os dados do emitente + //se for center separar 1/2 da altura para o logo e 1/2 para os dados + //se for right separa 2/3 para os dados e o terço seguinte para o logo + //se não houver logo centraliza dos dados do emitente + $force = true; + // coloca o logo + if (!empty($this->logomarca)) { + $logoInfo = getimagesize($this->logomarca); + //largura da imagem em mm + $logoWmm = ($logoInfo[0] / 72) * 25.4; + //altura da imagem em mm + $logoHmm = ($logoInfo[1] / 72) * 25.4; + if ($this->logoAlign === 'L') { + $nImgW = round($w / 3, 0); + $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0); + $xImg = $x; + $yImg = round(($h - $nImgH) / 2, 0) + $y; + //estabelecer posições do texto + $x1 = round($xImg + $nImgW, 0); + $y1 = round($h / 8 + $y, 0); + $y2 = $y1; + $tw = $w - $nImgW; + $force = false; + } elseif ($this->logoAlign === 'C') { + $nImgH = round($h / 3, 0); + $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0); + $xImg = round(($w - $nImgW) / 2 + $x, 0); + $yImg = $y + 3; + $x1 = $x+1; + $y1 = round($yImg + $nImgH+1, 0); + $y2 = $y1; + $tw = $w; + } elseif ($this->logoAlign === 'R') { + $nImgW = round($w / 3, 0); + $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0); + $xImg = round($x + ($w - (1 + $nImgW)), 0); + $yImg = round(($h - $nImgH) / 2, 0) + $y; + $x1 = $x; + $y1 = round($h / 8 + $y, 0); + $y2 = $y1; + $tw = $w - $nImgW; + $force = false; + } elseif ($this->logoAlign === 'F') { + $nImgH = round($h - 5, 0); + $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0); + $xImg = round(($w - $nImgW) / 2 + $x, 0); + $yImg = $y + 3; + $x1 = $x; + $y1 = round($yImg + $nImgH + 1, 0); + $tw = $w; + } + $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null; + $this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, 'jpeg'); + } else { + $x1 = $x; + $y1 = round($h / 3 + $y, 0); + $tw = $w; + } + // monta as informações apenas se diferente de full logo + if ($this->logoAlign !== 'F') { + //Nome emitente + $aFont = ['font' => $this->fontePadrao, 'size' => 12, 'style' => 'B']; + $texto = $this->std->emit->xNome; + $this->pdf->textBox($x1 - 1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '', $force); + if (!$force) { + $lines = $this->pdf->getNumLines($texto, $tw, $aFont); + $y2 = $y2 + $lines * 6; + } else { + $y2 += 5; + } + //endereço + $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => '']; + $fone = $this->std->emit->enderEmit->fone ?? ''; + $lgr = $this->std->emit->enderEmit->xLgr; + $nro = $this->std->emit->enderEmit->nro; + $cpl = $this->std->emit->enderEmit->xCpl ?? ''; + $bairro = $this->std->emit->enderEmit->xBairro; + $CEP = $this->std->emit->enderEmit->CEP; + $CEP = $this->formatField($CEP, "#####-###"); + $mun = $this->std->emit->enderEmit->xMun; + $UF = $this->std->emit->enderEmit->UF; + $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - " + . $CEP . "\n" . $mun . " - " . $UF . " " + . "Fone/Fax: " . $fone; + $this->pdf->textBox($x1-1, $y2, $tw, 8, $texto, $aFont, 'T', 'C', 0, ''); + } + //#################################################################################### + //coluna central Danfe + $x = $this->margesq + $w; + $texto = "DANFE"; + $aFont = ['font' => $this->fontePadrao, 'size' => 14, 'style' => 'B']; + $this->pdf->textBox($x, $y + 1, $w1, $h1, $texto, $aFont, 'T', 'C', 0, '', true); + $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => '']; + $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica'; + $this->pdf->textBox($x, $y + 6, $w1, $h1, $texto, $aFont, 'T', 'C', 0, '', false); + $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => '']; + $texto = '0 - ENTRADA'; + $y1 = $y + 14; + $this->pdf->textBox($x + 2, $y1, $w1/2, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = '1 - SAÍDA'; + $y1 = $y + 17; + $this->pdf->textBox($x + 2, $y1, $w1/2, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + //tipo de nF + $aFont = ['font' => $this->fontePadrao, 'size' => 12, 'style' => 'B']; + $y1 = $y + 13; + $texto = $this->std->ide->tpNF; + $this->pdf->textBox($x+$w1/2+$w2/10, $y1, 5, $h1, $texto, $aFont, 'C', 'C', 1, ''); + //numero da NF + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $y1 = $y + 22; + $texto = "Nº. " . $this->numero; + $this->pdf->textBox($x, $y1, $w1, 7, $texto, $aFont, 'T', 'C', 0, '', true); + //Série + $y1 = $y + 25; + $texto = "Série " . $this->serie; + $this->pdf->textBox($x, $y1, $w1, 7, $texto, $aFont, 'T', 'C', 0, '', true); + //numero paginas + $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'I']; + $y1 = $y + 28; + $texto = "Folha " . $pagina . "/" . $totalPaginas; + $this->pdf->textBox($x, $y1, $w1, 7, $texto, $aFont, 'T', 'C', 0, '', true); + //#################################################################################### + //coluna codigo de barras + $this->pdf->setFillColor(0, 0, 0); + $chave_acesso = str_replace('NFe', '', $this->std->attributes->Id); + $bW = $w2-4; + $bH = 12; + //codigo de barras + $this->pdf->code128($this->margesq + $w + $w1 + 2, $y + 2, $chave_acesso, $bW, $bH); + //linhas divisorias horizontais + $x = $this->margesq + $w + $w1; + $this->pdf->line($x, $y + 4 + $bH, $this->wPrint+$this->margesq, $y + 4 + $bH); + $this->pdf->line($x, $y + 12 + $bH, $this->wPrint+$this->margesq, $y + 12 + $bH); + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $y1 = $y + 4 + $bH; + $texto = 'CHAVE DE ACESSO'; + $this->pdf->textBox($x, $y1, $w, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + $aFont = ['font' => $this->fontePadrao, 'size' => 9, 'style' => 'B']; + $y1 = $y + 8 + $bH; + $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####"; + $texto = $this->formatField($chave_acesso, $formatoChave); + $this->pdf->textBox($x + 2, $y1, $w2 - 2, $h1, $texto, $aFont, 'T', 'C', 0, '', true); + $y1 = $y + 12 + $bH; + $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => '']; + $chaveContingencia = ""; + if (!empty($this->epec) && $this->std->ide->tpEmis == '4') { + $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO EPEC'; + } else { + $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO'; + } + //tpEmiss = 2 FS-IA não é mais autorizado somente está aqui para efeitos retroativos + //esse tipo de formulario não é mais fabricado + if (($this->std->ide->tpEmis == 2 || $this->std->ide->tpEmis == 5)) { + $cabecalhoProtoAutorizacao = "DADOS DA NF-E"; + $chaveContingencia = $this->geraChaveAdicionalDeContingencia(); + $this->pdf->setFillColor(0, 0, 0); + //codigo de barras + $this->pdf->code128($x + 11, $y1 + 1, $chaveContingencia, $bW * .9, $bH / 2); + } else { + $texto = 'Consulta de autenticidade no portal nacional da NF-e'; + $this->pdf->textBox($x + 2, $y1, $w - 2, $h1, $texto, $aFont, 'T', 'C', 0, ''); + $y1 = $y + 16 + $bH; + $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'; + $this->pdf->textBox( + $x + 2, + $y1, + $w - 2, + $h1, + $texto, + $aFont, + 'T', + 'C', + 0, + 'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora' + ); + } + //#################################################################################### + //Dados da NF do cabeçalho + $x = $this->margesq; + $y1 = $y+$h; + $texto = 'NATUREZA DA OPERAÇÃO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y1, $w+$w1, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->ide->natOp; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y1+1.8, $w+$w1, $h1, $texto, $aFont, 'T', 'C', 0, '', true); + + //linhas divisorias horizontais + $this->pdf->line($x, $y1+$h1, $this->wPrint+$this->margesq, $y1+$h1); + + //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E + $x += $w+$w1; + $prot = ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y1, $w2, $h1, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 0, '', true); + // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser + // testada antes de tentar obter a informação. + // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!! + // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização. + // Na minha opinião, deveríamos mostra-lo, mas o manual da NFe v4.01 diz outra coisa... + if (($this->std->ide->tpEmis == 2 || $this->std->ide->tpEmis == 5) && empty($this->epec)) { + $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'B']; + $texto = $this->formatField( + $chaveContingencia, + "#### #### #### #### #### #### #### #### ####" + ); + } else { + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + if (!empty($this->epec)) { + $prot = $this->epec['protocolo'] . ' - ' . $this->epec['data']; + } else { + if (!empty($this->protNFe)) { + $nProt = $this->protNFe->infProt->nProt; + $dtHora = \DateTime::createFromFormat('Y-m-d\TH:i?sP', $this->protNFe->infProt->dhRecbto) + ->format('d/m/Y H:i:s'); + $prot = $nProt . ' - ' . $dtHora; + } + } + } + $this->pdf->textBox($x, $y1+2, $w2, $h1, $prot, $aFont, 'T', 'C', 0, '', true); + //#################################################################################### + //linhas divisorias verticais + $x = $this->margesq; + $y1 += $h1; + $this->pdf->line($x+$w3, $y1, $x+$w3, $y1+$h1); + $this->pdf->line($x+2*$w3, $y1, $x+2*$w3, $y1+$h1); + $this->pdf->line($x+3*$w3, $y1, $x+3*$w3, $y1+$h1); + //INSCRIÇÃO ESTADUAL + $texto = 'INSCRIÇÃO ESTADUAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y1, $w3, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->emit->IE; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y1+2, $w3, $h1, $texto, $aFont, 'T', 'C', 0, '', true); + //INSCRIÇÃO MUNICIPAL + $x += $w3; + $texto = 'INSCRIÇÃO MUNICIPAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y1, $w3, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->emit->IM ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y1+2, $w3, $h1, $texto, $aFont, 'T', 'C', 0, '', true); + //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT. + $x += $w3; + $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y1, $w3, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->emit->IEST ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y1+2, $w3, $h1, $texto, $aFont, 'T', 'C', 0, '', true); + //CNPJ + $x += $w3; + $texto = 'CNPJ / CPF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y1, $w3-$this->margesq, $h1, $texto, $aFont, 'T', 'L', 0, '', true); + //Pegando valor do CPF/CNPJ + $texto = ''; + if (!empty($this->std->emit->CNPJ)) { + $texto = $this->formatField( + $this->std->emit->CNPJ, + "###.###.###/####-##" + ); + } else { + if (!empty($this->std->emit->CPF)) { + $texto = $this->formatField($this->std->emit->CPF,"###.###.###-##"); + } + } + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y1+2, $w3-$this->margesq, $h1, $texto, $aFont, 'T', 'C', 0, '', true); + return 46; + } + + protected function headerL(float $y, $pagina = 1, $totalPaginas = 1): float + { + return 46; + } +} diff --git a/src/NFe/Traits/TraitImpostosNfe.php b/src/NFe/Traits/TraitImpostosNfe.php new file mode 100644 index 00000000..dcfb97b3 --- /dev/null +++ b/src/NFe/Traits/TraitImpostosNfe.php @@ -0,0 +1,121 @@ +orientacao}"; + return $this->$imp($y); + } + + public function impostosP(float $y): float + { + $x = $this->margesq; + $campos_por_linha = 9; + $h = 7; + $title_size = 31; + $w = $this->wPrint / $campos_por_linha; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y+3, $this->wPrint, 14, '', $aFont, 'T', 'L', 1, ''); + $fontTitulo = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $fontValor = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + //linha horizontal + $this->pdf->line($x, $y+10, $this->wPrint+$this->margesq, $y+10); + //linhas verticais + $this->pdf->line($x+$w, $y+3, $x+$w, $y+17); + $this->pdf->line($x+2*$w, $y+3, $x+2*$w, $y+17); + $this->pdf->line($x+3*$w, $y+3, $x+3*$w, $y+17); + $this->pdf->line($x+4*$w, $y+3, $x+4*$w, $y+17); + $this->pdf->line($x+5*$w, $y+3, $x+5*$w, $y+17); + $this->pdf->line($x+6*$w, $y+3, $x+6*$w, $y+17); + $this->pdf->line($x+7*$w, $y+3, $x+7*$w, $y+17); + $this->pdf->line($x+8*$w, $y+3, $x+8*$w, $y+17); + $texto = "CÁLCULO DO IMPOSTO"; + $this->pdf->textBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, ''); + $y += 3; + //valores + $val = $this->std->total->ICMSTot; + //vBC + $this->pdf->textBox($x, $y, $w, $h, 'BASE DE CÁLC. DO ICMS', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vBC, 2, ',', '.'); + $this->pdf->textBox($x, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //vICMS + $this->pdf->textBox($x+$w, $y, $w, $h, 'VALOR DO ICMS', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vICMS, 2, ',', '.'); + $this->pdf->textBox($x+$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //vBCST + $this->pdf->textBox($x+2*$w, $y, $w, $h, 'BASE DE CÁLC. ICMS S.T', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vBCST ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+2*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //VALOR DO ICMS SUBST. + $this->pdf->textBox($x+3*$w, $y, $w, $h, 'VALOR DO ICMS SUBST.', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vST ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+3*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //V. IMP. IMPORTAÇÃO + $this->pdf->textBox($x+4*$w, $y, $w, $h, 'V. IMP. IMPORTAÇÃO', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vII ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+4*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //V. ICMS UF REMET. + $this->pdf->textBox($x+5*$w, $y, $w, $h, 'V. ICMS UF REMET.', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vICMSUFRemet ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+5*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //V. FCP UF DEST. + $this->pdf->textBox($x+6*$w, $y, $w, $h, 'V. FCP UF DEST.', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vFCPUFDest ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+6*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //VALOR DO PIS + $this->pdf->textBox($x+7*$w, $y, $w, $h, 'VALOR DO PIS', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vPIS ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+7*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //V. TOTAL PRODUTOS + $this->pdf->textBox($x+8*$w, $y, $w, $h, 'V. TOTAL PRODUTOS', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vProd ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+8*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + $y += $h; + //VALOR DO FRETE + $this->pdf->textBox($x, $y, $w, $h, 'VALOR DO FRETE', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vFrete ?? 0, 2, ',', '.'); + $this->pdf->textBox($x, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //VALOR DO SEGURO + $this->pdf->textBox($x+$w, $y, $w, $h, 'VALOR DO SEGURO', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vSeg ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //DESCONTO + $this->pdf->textBox($x+2*$w, $y, $w, $h, 'DESCONTO', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vDesc ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+2*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //OUTRAS DESPESAS + $this->pdf->textBox($x+3*$w, $y, $w, $h, 'OUTRAS DESPESAS', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vOutro ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+3*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //VALOR TOTAL IPI + $this->pdf->textBox($x+4*$w, $y, $w, $h, 'VALOR TOTAL IPI', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vIPI ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+4*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //V. ICMS UF DEST. + $this->pdf->textBox($x+5*$w, $y, $w, $h, 'V. ICMS UF DEST.', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vICMSUFDest ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+5*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //V. TOT. TRIB. + $this->pdf->textBox($x+6*$w, $y, $w, $h, 'V. TOT. TRIB.', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vTotTrib ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+6*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //VALOR DA COFINS + $this->pdf->textBox($x+7*$w, $y, $w, $h, 'VALOR DA COFINS', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vCOFINS ?? 0, 2, ',', '.'); + $this->pdf->textBox($x+7*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + //V. TOTAL DA NOTA + $this->pdf->textBox($x+8*$w, $y, $w, $h, 'V. TOTAL DA NOTA', $fontTitulo, 'T', 'L', 0, ''); + $valor = number_format($val->vNF, 2, ',', '.'); + $this->pdf->textBox($x+8*$w, $y, $w, $h, $valor, $fontValor, 'B', 'R', 0, ''); + return 17; + } + + public function impostosL(float $y): float + { + return 0; + } + +} diff --git a/src/NFe/Traits/TraitItensNfe.php b/src/NFe/Traits/TraitItensNfe.php new file mode 100644 index 00000000..e582568a --- /dev/null +++ b/src/NFe/Traits/TraitItensNfe.php @@ -0,0 +1,476 @@ +orientacao}"; + $this->$ins($y, $h, $itens); + } + + public function insertItensP(float $y, float $h, array $itens) + { + $x = $this->margesq; + $oldX = $x; + $oldY = $y; + //##################################################################### + //DADOS DOS PRODUTOS / SERVIÇOS + $texto = "DADOS DOS PRODUTOS / SERVIÇOS"; + $w = $this->wPrint; + $hh = 4; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $hh, $texto, $aFont, 'T', 'L', 0, ''); + $y += 3; + //desenha a caixa dos dados dos itens da NF + $this->pdf->textBox($x, $y, $w, $h); + //################################################################################## + // cabecalho LOOP COM OS DADOS DOS PRODUTOS + //CÓDIGO PRODUTO + $texto = "CÓDIGO PRODUTO"; + $w1 = round($w * 0.09, 0); + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w1, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w1, $y, 0.1, $y + $h, 100); + //DESCRIÇÃO DO PRODUTO / SERVIÇO + $x += $w1; + $w2 = round($w * 0.25, 0); + $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w2, $y, 0.1, $y + $h, 100); + //NCM/SH + $x += $w2; + $w3 = round($w * 0.06, 0); + $texto = 'NCM/SH'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w3, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w3, $y, 0.1, $y + $h, 100); + //O/CST ou O/CSOSN + $x += $w3; + $w4 = round($w * 0.05, 0); + $texto = 'O/CST'; // CRT = 2 ou CRT = 3 + if ($this->std->emit->CRT == '1') { + $texto = 'O/CSOSN'; //Regime do Simples CRT = 1 + } + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w4, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w4, $y, 0.1, $y + $h, 100); + //CFOP + $x += $w4; + $w5 = round($w * 0.04, 0); + $texto = 'CFOP'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w5, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w5, $y, 0.1, $y + $h, 100); + //UN + $x += $w5; + $w6 = round($w * 0.03, 0); + $texto = 'UN'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w6, $y, 0.1, $y + $h, 100); + //QUANT + $x += $w6; + $w7 = round($w * 0.08, 0); + $texto = 'QUANT'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w7, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w7, $y, 0.1, $y + $h, 100); + //VALOR UNIT + $x += $w7; + $w8 = round($w * 0.06, 0); + $texto = 'VALOR UNIT'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w8, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w8, $y, 0.1, $y + $h, 100); + //VALOR TOTAL + $x += $w8; + $w9 = round($w * 0.06, 0); + $texto = 'VALOR TOTAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w9, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w9, $y, 0.1, $y + $h, 100); + //VALOR DESCONTO + $x += $w9; + $w10 = round($w * 0.05, 0); + $texto = 'VALOR DESC'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w10, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w10, $y, 0.1, $y + $h, 100); + //B.CÁLC ICMS + $x += $w10; + $w11 = round($w * 0.06, 0); + $texto = 'B.CÁLC ICMS'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w11, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w11, $y, 0.1, $y + $h, 100); + //VALOR ICMS + $x += $w11; + $w12 = round($w * 0.06, 0); + $texto = 'VALOR ICMS'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w12, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w12, $y, 0.1, $y + $h, 100); + //VALOR IPI + $x += $w12; + $w13 = round($w * 0.05, 0); + $texto = 'VALOR IPI'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w13, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w13, $y, 0.1, $y + $h, 100); + //ALÍQ. ICMS + $x += $w13; + $w14 = round($w * 0.04, 0); + $texto = 'ALÍQ. ICMS'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w14, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->dashedVLine($x + $w14, $y, 0.1, $y + $h, 100); + //ALÍQ. IPI + $x += $w14; + $w15 = $w - ($w1 + $w2 + $w3 + $w4 + $w5 + $w6 + $w7 + $w8 + $w9 + $w10 + $w11 + $w12 + $w13 + $w14); + $texto = 'ALÍQ. IPI'; + $this->pdf->textBox($x, $y, $w15, $hh, $texto, $aFont, 'C', 'C', 0, '', false); + $this->pdf->line($oldX, $y + $hh + 1, $oldX + $w, $y + $hh + 1); + $y += 5; + $x = $this->margesq; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => '']; + $tot = count($itens); + $i = 1; + foreach($itens as $item) { + $numero = 'item '.$item['n']; + $std = $item['std']; + $codigo = "{$std->prod->cProd}"; + if ($this->exibirNumeroDet) { + $codigo = "[{$numero}]\n{$std->prod->cProd}"; + } + $hitem = $item['heigth']; + $this->pdf->textBox($x, $y, $w1, $hitem, $codigo, $aFont, 'T', 'C', 0, ''); + $texto = $item['texto']; + $this->pdf->textBox($x+$w1, $y, $w2, $hitem, $texto, $aFont, 'T', 'L', 0, '', false); + $ncm = $std->prod->NCM; + $this->pdf->textBox($x+$w1+$w2, $y, $w3, $hitem, $ncm, $aFont, 'T', 'C', 0, ''); + $bloco = $item['bloco']; + $cst = $std->imposto->ICMS->$bloco->CST ?? ''; + $csosn = $std->imposto->ICMS->$bloco->CSOSN ?? ''; + $ocst = $std->imposto->ICMS->$bloco->orig .'/'. $cst . $csosn; + $this->pdf->textBox($x+$w1+$w2+$w3, $y, $w4, $hitem, $ocst, $aFont, 'T', 'C', 0, ''); + $cfop = $std->prod->CFOP; + $this->pdf->textBox($x+$w1+$w2+$w3+$w4, $y, $w5, $hitem, $cfop, $aFont, 'T', 'C', 0, ''); + $ucom = $std->prod->uCom; + $utrib = $std->prod->uTrib; + $unidade = $ucom; + if ($ucom != $utrib && $this->mostrarUnidadeTributavel) { + $texto .= "\n".$utrib; + } + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5, $y, $w6, $hitem, $unidade, $aFont, 'T', 'C', 0, ''); + $qtdade = number_format($std->prod->qCom, 4, ',', '.'); + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6, $y, $w7, $hitem, $qtdade, $aFont, 'T', 'R', 0, ''); + $vuncom = number_format($std->prod->vUnCom, 4, ',', '.'); + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7, $y, $w8, $hitem, $vuncom, $aFont, 'T', 'R', 0, ''); + $vprod = number_format($std->prod->vProd, 2, ',', '.'); + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8, $y, $w9, $hitem, $vprod, $aFont, 'T', 'R', 0, ''); + $vdesc = !empty($std->prod->vDesc) ? number_format($std->prod->vDesc, 2, ',', '.') : ''; + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9, $y, $w10, $hitem, $vdesc, $aFont, 'T', 'R', 0, ''); + $imp = $std->imposto->ICMS->$bloco; + $vbc = !empty($imp->vBC) ? number_format($imp->vBC, 2, ',', '.') : ''; + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10, $y, $w11, $hitem, $vbc, $aFont, 'T', 'R', 0, ''); + $vicms = !empty($imp->vICMS) ? number_format($imp->vICMS, 2, ',', '.') : ''; + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11, $y, $w12, $hitem, $vicms, $aFont, 'T', 'R', 0, ''); + $vipi = !empty($std->imposto->IPI->IPITrib->vIPI) ? number_format($std->imposto->IPI->vIPI, 2, ',', '.') : ''; + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12, $y, $w13, $hitem, $vipi, $aFont, 'T', 'R', 0, ''); + $alqicms = !empty($imp->pICMS) ? number_format($imp->pICMS, 2, ',', '') : ''; + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13, $y, $w14, $hitem, $alqicms, $aFont, 'T', 'R', 0, ''); + $alqipi = !empty($std->imposto->IPI->IPITrib->pIPI) ? number_format($std->imposto->IPI->IPITrib->pIPI, 2, ',', '') : ''; + $this->pdf->textBox($x+$w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13+$w14, $y, $w15, $hitem, $alqipi, $aFont, 'T', 'R', 0, ''); + $i++; + if ($i <= $tot) { + $this->pdf->dashedHLine(2, $y + $hitem, $this->wPrint, 0.1, 80); + } + $y += $hitem; + } + + /* + //################################################################################## + // LOOP COM OS DADOS DOS PRODUTOS + $i = 0; + $hUsado = $hCabecItens; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => '']; + + foreach ($this->det as $d) { + if ($i >= $nInicio) { + $thisItem = $this->det->item($i); + //carrega as tags do item + $prod = $thisItem->getElementsByTagName("prod")->item(0); + $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0); + $ICMS = $imposto->getElementsByTagName("ICMS")->item(0); + $IPI = $imposto->getElementsByTagName("IPI")->item(0); + $textoProduto = $this->descricaoProduto($thisItem); + //$veicProd = $prod->getElementsByTagName("veicProd")->item(0); + + // Posição y dos dados das unidades tributaveis. + $yTrib = $this->pdf->fontSize + .5; + + $uCom = $prod->getElementsByTagName("uCom")->item(0)->nodeValue; + $vUnCom = $prod->getElementsByTagName("vUnCom")->item(0)->nodeValue; + $uTrib = $prod->getElementsByTagName("uTrib")->item(0); + $qTrib = $prod->getElementsByTagName("qTrib")->item(0); + $cfop = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue; + $vUnTrib = !empty($prod->getElementsByTagName("vUnTrib")->item(0)->nodeValue) + ? $prod->getElementsByTagName("vUnTrib")->item(0)->nodeValue + : 0; + // A Configuração serve para informar se irá exibir + // de forma obrigatória, estando diferente ou não, + // a unidade de medida tributária. + // ======== + // A Exibição será realizada sempre que a unidade comercial for + // diferente da unidade de medida tributária. + // "Nas situações em que o valor unitário comercial for diferente do valor unitário tributável, + // ambas as informações deverão estar expressas e identificadas no DANFE, podendo ser + // utilizada uma das linhas adicionais previstas, ou o campo de informações adicionais." + // > Manual Integração - Contribuinte 4.01 - NT2009.006, Item 7.1.5, página 91. + $mostrarUnidadeTributavel = (!$this->ocultarUnidadeTributavel + && !empty($uTrib) + && !empty($qTrib) + && number_format($vUnCom, 2, ',', '') !== number_format($vUnTrib, 2, ',', '') + ); + + // Informação sobre unidade de medida tributavel. + // Se não for para exibir a unidade de medida tributavel, então + // A Escrita irá começar em 0. + if (!$mostrarUnidadeTributavel) { + $yTrib = 0; + } + $h = $this->calculeHeight($thisItem, $mostrarUnidadeTributavel); + $hUsado += $h; + + $yTrib += $y; + $diffH = $hmax - $hUsado; + + if (1 > $diffH && $i < $totItens) { + if ($pag == $totpag) { + $totpag++; + } + //ultrapassa a capacidade para uma única página + //o restante dos dados serão usados nas proximas paginas + $nInicio = $i; + break; + } + + $y_linha = $y + $h; + + //corrige o x + $x = $oldX; + //codigo do produto + $guup = $i + 1; + $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue; + $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, ''); + $x += $w1; + + //DESCRIÇÃO + if ($this->orientacao === 'P') { + $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false); + } else { + $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false); + } + $x += $w2; + //NCM + $texto = !empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ? + $prod->getElementsByTagName("NCM")->item(0)->nodeValue : ''; + $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, ''); + $x += $w3; + + //GRUPO DE VEICULO NOVO + $oldfont = $aFont; + $veicnovo = $this->itemVeiculoNovo($prod); + $aFont = ['font' => $this->fontePadrao, 'size' => 5, 'style' => '']; + $this->pdf->textBox( + $x-$w3, + $y+4, + $this->wPrint-($w1+$w2)-2, + 22, + $veicnovo, + $aFont, + 'T', + 'L', + 0, + '', + true, + 0, + 0, + false + ); + $aFont = $oldfont; + //CST + if (isset($ICMS)) { + $origem = $this->getTagValue($ICMS, "orig"); + $cst = $this->getTagValue($ICMS, "CST"); + $csosn = $this->getTagValue($ICMS, "CSOSN"); + $texto = $origem . "/" . $cst . $csosn; + $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, ''); + } + //CFOP + $x += $w4; + $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue; + $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, ''); + //Unidade + $x += $w5; + $texto = $uCom; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, ''); + //Unidade de medida tributável + $qTrib = $prod->getElementsByTagName("qTrib")->item(0)->nodeValue; + if ($mostrarUnidadeTributavel) { + $texto = $uTrib->nodeValue; + $this->pdf->textBox($x, $yTrib, $w6, $h, $texto, $aFont, 'T', 'C', 0, ''); + } + $x += $w6; + if ($this->orientacao == 'P') { + $alinhamento = 'R'; + } else { + $alinhamento = 'R'; + } + // QTDADE + $qCom = $prod->getElementsByTagName("qCom")->item(0); + $texto = number_format($qCom->nodeValue, $this->qComCasasDec, ",", "."); + $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + // QTDADE Tributável + if ($mostrarUnidadeTributavel) { + $qTrib = $prod->getElementsByTagName("qTrib")->item(0); + if (!empty($qTrib)) { + $texto = number_format($qTrib->nodeValue, $this->qComCasasDec, ",", "."); + $this->pdf->textBox($x, $yTrib, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + } + } + $x += $w7; + // Valor Unitário + $vUnCom = $prod->getElementsByTagName("vUnCom")->item(0); + $texto = number_format($vUnCom->nodeValue, $this->vUnComCasasDec, ",", "."); + $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + // Valor Unitário Tributável + if ($mostrarUnidadeTributavel) { + $vUnTrib = $prod->getElementsByTagName("vUnTrib")->item(0); + if (!empty($vUnTrib)) { + $texto = number_format($vUnTrib->nodeValue, $this->vUnComCasasDec, ",", "."); + $this->pdf->textBox($x, $yTrib, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + } + } + $x += $w8; + // Valor do Produto + $texto = ""; + if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) { + $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", "."); + } + $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + $x += $w9; + //Valor do Desconto + $vdesc = !empty($prod->getElementsByTagName("vDesc")->item(0)->nodeValue) + ? $prod->getElementsByTagName("vDesc")->item(0)->nodeValue : 0; + + $texto = number_format($vdesc, 2, ",", "."); + $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + //Valor da Base de calculo + $x += $w10; + if (isset($ICMS)) { + $texto = !empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) + ? number_format( + $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue, + 2, + ",", + "." + ) + : '0,00'; + $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + } + //Valor do ICMS + $x += $w11; + if (isset($ICMS)) { + $texto = !empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) + ? number_format( + $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue, + 2, + ",", + "." + ) + : '0,00'; + $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + } + //Valor do IPI + $x += $w12; + if (isset($IPI)) { + $texto = !empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) + ? number_format( + $IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, + 2, + ",", + "." + ) + : ''; + } else { + $texto = ''; + } + $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); + // %ICMS + $x += $w13; + if (isset($ICMS)) { + $texto = !empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) + ? number_format( + $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue, + 2, + ",", + "." + ) + : '0,00'; + $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, ''); + } + //%IPI + $x += $w14; + if (isset($IPI)) { + $texto = !empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) + ? number_format( + $IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, + 2, + ",", + "." + ) + : ''; + } else { + $texto = ''; + } + $this->pdf->textBox($x, $y, $w15, $h, $texto, $aFont, 'T', 'C', 0, ''); + + + // Dados do Veiculo Somente para veiculo 0 Km + $veicProd = $prod->getElementsByTagName("veicProd")->item(0); + // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran + // Verifica se a Tag existe + if (!empty($veicProd)) { + $y += $h - 10; + $this->dadosItenVeiculoDANFE($oldX + 3, $y, $nInicio, 3, $prod); + // linha entre itens + $this->pdf->dashedHLine($oldX, $y + 30, $w, 0.1, 120); + $y += 30; + $hUsado += 30; + } else { + // linha entre itens + $this->pdf->dashedHLine($oldX, $y, $w, 0.1, 120); + } + $y += $h; + $i++; + //incrementa o controle dos itens processados. + $this->qtdeItensProc++; + } else { + $i++; + } + }*/ + + } + + public function insertItensL(float $y, float $h, array $itens) + { + + } + + + +} diff --git a/src/NFe/Traits/TraitLocalRetiradaEntregaNfe.php b/src/NFe/Traits/TraitLocalRetiradaEntregaNfe.php new file mode 100644 index 00000000..9c4bf453 --- /dev/null +++ b/src/NFe/Traits/TraitLocalRetiradaEntregaNfe.php @@ -0,0 +1,140 @@ +orientacao}"; + return $this->$local($y, $tipo); + } + + protected function localP(float $y, string $tipo): float + { + $x = $this->margesq; + $h = 7; + $htot = 21; + $w = round($this->wPrint * 0.61, 0); + $w1 = round($this->wPrint * 0.23, 0); //cnpj + $w2 = $this->wPrint - $w - $w1; //ie + $w3 = round($this->wPrint * 0.52, 0); //endereço + $w4 = $this->wPrint - $w3 - $w2; + $wuf = 8; + $w5 = $this->wPrint - $wuf - $w2; + + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => '']; + //borda do bloco de informações + $this->pdf->textBox($x, $y+3, $this->wPrint, $htot, '', $aFont, 'T', 'L', 1, ''); + //linhas horizontais + $this->pdf->line($x, $y+10, $this->wPrint+$this->margesq, $y+10); + $this->pdf->line($x, $y+17, $this->wPrint+$this->margesq, $y+17); + //linhas verticais + $this->pdf->line($x+$w, $y+3, $x+$w, $y+10); // nome | cnpj + $this->pdf->line($x+$w+$w1, $y+3, $x+$w+$w1, $y+24); // cnpj | ie + $this->pdf->line($x+$w3, $y+10, $x+$w3, $y+17); // endereço | bairro + $this->pdf->line($x+$w5, $y+17, $x+$w5, $y+24); // municipio | uf + + //#################################################################################### + //LOCAL DE RETIRADA ou de ENTREGA + $texto = "INFORMAÇÕES DO LOCAL DE {$tipo}"; + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //NOME / RAZÃO SOCIAL + $y += 3; + $texto = 'NOME / RAZÃO SOCIAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->xNome ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //CNPJ / CPF + $x += $w; + $texto = 'CNPJ / CPF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //Pegando valor do CPF/CNPJ + $texto = ''; + $doc = $this->std->retirada->CNPJ ?? ''; + if (!empty($doc)) { + $texto = $this->formatField($doc,"###.###.###/####-##"); + } else { + $doc = $this->std->retirada->CPf ?? ''; + $texto = $this->formatField($this->std->retirada->CPF ?? '', "###.###.###-##"); + } + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w1, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //INSCRIÇÃO ESTADUAL + $x += $w1; + $texto = 'INSCRIÇÃO ESTADUAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->IE ?? '123456'; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w2, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //ENDEREÇO + $y += $h; + $x = $this->margesq; + $texto = 'ENDEREÇO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->xLgr ?? ''; + $texto .= ', ' . $this->std->retirada->nro ?? ''; + $texto .= ' '. $this->std->retirada->xCpl ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w3, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //BAIRRO / DISTRITO + $x += $w3; + $texto = 'BAIRRO / DISTRITO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->xBairro ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w4, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //CEP + $x += $w4; + $texto = 'CEP'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->CEP ?? '12345000'; + $texto = $this->formatField($texto, "#####-###"); + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w2, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //MUNICÍPIO + $y += $h; + $x = $this->margesq; + $texto = 'MUNICÍPIO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->xMun ?? ''; + if (!empty($this->std->retirada->xPais) && strtoupper(trim($texto)) === "EXTERIOR") { + $texto .= " - " . $this->std->xPais; + } + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w5, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //UF + $x += $w5; + $texto = 'UF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $wuf, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->UF; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $wuf, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //FONE / FAX + $x += $wuf; + $texto = 'FONE / FAX'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->retirada->fone ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w2, $h, $texto, $aFont, 'T', 'C', 0, '', true); + return 24; + } + + protected function localL(float $y, string $tipo) + { + return 0; + } + +} diff --git a/src/NFe/Traits/TraitRodapeNfe.php b/src/NFe/Traits/TraitRodapeNfe.php new file mode 100644 index 00000000..957b7476 --- /dev/null +++ b/src/NFe/Traits/TraitRodapeNfe.php @@ -0,0 +1,24 @@ +margesq; + $y = $this->maxH - 4; + if ($this->orientacao == 'P') { + $w = $this->wPrint; + } else { + $w = $this->wPrint - $this->wCanhoto; + $x = $this->wCanhoto; + } + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => 'I']; + $texto = "Impresso em " . date('d/m/Y') . " as " . date('H:i:s') + . ' ' . $this->creditos; + $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false); + $texto = $this->powered ? "Powered by NFePHP®" : ''; + $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, ''); + } +} diff --git a/src/NFe/Traits/TraitTransportadorNfe.php b/src/NFe/Traits/TraitTransportadorNfe.php new file mode 100644 index 00000000..294be447 --- /dev/null +++ b/src/NFe/Traits/TraitTransportadorNfe.php @@ -0,0 +1,290 @@ +orientacao}"; + return $this->$trans($y); + } + + public function transportadorP(float $y): float + { + $tipoFrete = $this->std->transp->modFrete ?? 0; + if ($tipoFrete == 9) { + return 0; + } + $x = $this->margesq; + $h = 7; + $w1 = round($this->wPrint * 0.29, 0); + $w6 = round($this->wPrint/6, 0); + $wuf = 8; + $w2 = ($this->wPrint - $w1 -$w6 - $wuf) / 3; + $w3 = $w1 + $w2; + $w4 = 2 * $w2; + + $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B']; + //borda do bloco + $this->pdf->textBox($x, $y+3, $this->wPrint, 21, '', $aFont, 'T', 'L', 1, ''); + //linhas horizontais + $this->pdf->line($x, $y+10, $this->wPrint+$this->margesq, $y+10); + $this->pdf->line($x, $y+17, $this->wPrint+$this->margesq, $y+17); + //linhas verticais + $this->pdf->line($x+$w1, $y+3, $x+$w1, $y+10); + $this->pdf->line($x+$w1+$w2, $y+3, $x+$w1+$w2, $y+24); + //$this->pdf->line($x+$w1+2*$w2, $y+3, $x+$w1+2*$w2, $y+10); + $this->pdf->line($x+$w1+3*$w2, $y+10, $x+$w1+3*$w2, $y+17); + $this->pdf->line($x+$w1+3*$w2+$wuf, $y+3, $x+$w1+3*$w2+$wuf, $y+24); + $this->pdf->line($x+$w6, $y+17, $x+$w6, $y+24); + $this->pdf->line($x+2*$w6, $y+17, $x+2*$w6, $y+24); + $this->pdf->line($x+4*$w6, $y+17, $x+4*$w6, $y+24); + + //##################################################################### + //TRANSPORTADOR / VOLUMES TRANSPORTADOS + $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS"; + $this->pdf->textBox($x, $y, $this->wPrint, 3, $texto, $aFont, 'T', 'L', 0, ''); + //NOME / RAZÃO SOCIAL + $y += 3; + $texto = 'NOME / RAZÃO SOCIAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 0, '',true); + $texto = $this->std->transp->transporta->xNome ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w1, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //FRETE POR CONTA + $x += $w1; + $texto = 'FRETE'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $tipoFrete = $this->std->transp->modFrete ?? 0; + switch ($tipoFrete) { + case 0: + $texto = "0- Por conta do Emitente"; + break; + case 1: + $texto = "1-Por conta do Destinatário"; + break; + case 2: + $texto = "2-Por conta de Terceiro"; + break; + case 3: + $texto = "3-Próprio por conta Remetente"; + break; + case 4: + $texto = "4-Próprio por conta Destinatário"; + break; + case 9: + $texto = "9-Sem Transporte"; + break; + } + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w2, $h, $texto, $aFont, 'T', 'C', 0, '', true); + if (!empty($this->std->transp->vagao) || !empty($this->std->transp->balsa)) { + //VAGÃO ou BALSA + $texto = 'BALSA'; + if (!empty($this->std->transp->vagao)) { + $texto = 'VAGÂO'; + } + $x += $w2; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, 2*$w2+$wuf, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $texto = $this->std->transp->vagao ?? $this->std->transp->balsa; + $this->pdf->textBox($x, $y+2, 2*$w2+$wuf, $h, $texto, $aFont, 'T', 'C', 0, '', true); + } else { + $this->pdf->line($this->margesq+$w1+2*$w2, $y, $this->margesq+$w1+2*$w2, $y+7); + $this->pdf->line($this->margesq+$w1+3*$w2, $y, $this->margesq+$w1+3*$w2, $y+7); + $this->pdf->line($this->margesq+$w1+3*$w2+$wuf, $y, $this->margesq+$w1+3*$w2+$wuf, $y+7); + //VEICULO ou REBOQUE + //CÓDIGO ANTT + $x += $w2; + $texto = 'CÓDIGO ANTT (RNTC)'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $vrntc = $this->std->transp->veicTransp->RNTC ?? ''; + $rrntc = $this->std->transp->reboque->RNTC ?? ''; + $texto = $vrntc . $rrntc; //RNTC do veiculo ou do reboque + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '', true); + //PLACA DO VEÍC / REBOQUE + $texto = 'PLACA DO VEÍCULO'; + if (!empty($this->std->transp->reboque)) { + $texto = 'PLACA DO REBOQUE'; + } + $x += $w2; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $veic = $this->std->transp->veicTransp->placa ?? ''; + $reb = $this->std->transp->reboque->placa ?? ''; + $texto = $veic . $reb; //placa do veiculo ou do reboque + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '', true); + //UF + $x += $w2; + $texto = 'UF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $wuf, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $vuf = $this->std->transp->veicTransp->UF ?? ''; + $ruf = $this->std->transp->reboque->UF ?? ''; + $texto = $vuf . $ruf; //uf do veiculo ou do reboque + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y, $wuf, $h, $texto, $aFont, 'B', 'C', 0, '', true); + } + //CNPJ / CPF + $x = $this->wPrint-$w6+$this->margesq; + $texto = 'CNPJ / CPF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $jdoc = $this->std->transp->transporta->CNPJ ?? ''; + $fdoc = $this->std->transp->transporta->CPF ?? ''; + $texto = ''; + if (!empty($jdoc)) { + $texto = $this->formatField($jdoc, "##.###.###/####-##"); + } elseif (!empty($fdoc)) { + $texto = $this->formatField($fdoc,"###.###.###-##"); + } + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //##################################################################### + //ENDEREÇO + $y += $h; + $x = $this->margesq; + $texto = 'ENDEREÇO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w1+$w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->transp->transporta->xEnder ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w1+$w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //MUNICÍPIO + $x += $w1+$w2; + $texto = 'MUNICÍPIO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, 2*$w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->transp->transporta->xMun ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, 2*$w2, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //UF + $x += 2*$w2; + $texto = 'UF'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $wuf, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $this->std->transp->transporta->UF ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $wuf, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //INSCRIÇÃO ESTADUAL + $x += $wuf; + $texto = 'INSCRIÇÃO ESTADUAL'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, ''); + $texto = $this->std->transp->transporta->IE ?? ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6, $h, $texto, $aFont, 'T', 'C', 0, ''); + //Tratar Multiplos volumes + $vol = $this->std->transp->vol; + if (is_array($vol)) { + $volumes = $vol; + } else { + $volumes[] = $vol; + } + $quantidade = 0; + $especie = ''; + $marca = ''; + $numero = ''; + $pesoBruto = 0; + $pesoLiquido = 0; + $esp = []; + $marcas = []; + $nvols = []; + foreach ($volumes as $volume) { + $quantidade += $volume->qVol ?? 0; + $pesoBruto += $volume->pesoB ?? 0; + $pesoLiquido += $volume->pesoL ?? 0; + if (!empty($volume->nVol)) { + $nvols[] = $volume->nVol; + } + if (!empty($volume->esp)) { + $esp[] = strtoupper(trim($volume->esp)); + } + if (!empty($volume->marca)) { + $marcas[] = strtoupper(trim($volume->marca)); + } + } + $esp = array_unique($esp); + $marcas = array_unique($marcas); + $nvols = array_unique($nvols); + if (count($esp) > 1) { + $especie = 'VÁRIAS'; + } else { + $especie = $esp[0] ?? ''; + } + if (count($marcas) > 1) { + $marca = 'VÁRIAS'; + } else { + $marca = $marcas[0] ?? ''; + } + if (count($nvols) > 1) { + $numero = 'VÁRIOS'; + } else { + $numero = $nvols[0] ?? ''; + } + //##################################################################### + //QUANTIDADE + $y += $h; + $x = $this->margesq; + $texto = 'QUANTIDADE'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = !empty($quantidade) ? $quantidade : ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //ESPÉCIE + $x += $w6; + $texto = 'ESPÉCIE'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $especie; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //MARCA + $x += $w6; + $texto = 'MARCA'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $marca; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6-7, $h, $texto, $aFont, 'T', 'L', 0, '', true); + //NUMERAÇÃO + $x += $w6-7; + $texto = 'NUMERAÇÃO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6+7, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = $numero; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6+7, $h, $texto, $aFont, 'T', 'C', 0, '', true); + //PESO BRUTO + $x = $this->wPrint-2*$w6+$this->margesq+2; + $texto = 'PESO BRUTO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = !empty($pesoBruto) ? number_format($pesoBruto, 3, ",", ".") : ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6-2, $h, $texto, $aFont, 'T', 'R', 0, '', true); + //PESO LÍQUIDO + $x = $this->wPrint-$w6+$this->margesq; + $texto = 'PESO LÍQUIDO'; + $aFont = ['font' => $this->fontePadrao, 'size' => 6, 'style' => '']; + $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'L', 0, '', true); + $texto = !empty($pesoLiquido) ? number_format($pesoLiquido, 3, ",", ".") : ''; + $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B']; + $this->pdf->textBox($x, $y+2, $w6, $h, $texto, $aFont, 'T', 'R', 0, '', true); + return 3*$h+3; + } + + public function transportadorL(float $y): float + { + return 0; + } + +} diff --git a/src/NFe/Traits/TraitWaterMark.php b/src/NFe/Traits/TraitWaterMark.php new file mode 100644 index 00000000..36d8dc92 --- /dev/null +++ b/src/NFe/Traits/TraitWaterMark.php @@ -0,0 +1,76 @@ +orientacao}"; + $this->$wm(); + } + + protected function waterMarkP() + { + $message = ''; + $submessage = ''; + if (empty($this->protNFe)) { + //não está protocolado + $message = 'IMPRESSÃO EM TESTE'; + $submessage = "SEM PROTOCOLO DE AUTORIZAÇÃO\nSEM VALOR FISCAL"; + } else { + if ($this->protNFe->infProt->cStat === '101') { + $message = 'NFe CANCELADA'; + $submessage = ''; + } + } + if (!empty($this->retEvento)) { + //pode estar cancelada + if ($this->retEvento->infEvento->tpEvento === '110111') { + $message = 'NFe CANCELADA'; + $dh = \DateTime::createFromFormat('Y-m-d\TH:i:sP', $this->retEvento->infEvento->dhRegEvento); + $protocolo = $this->retEvento->infEvento->nProt; + $submessage = "Data canc.: " . $dh->format('d/m/Y H:i:s') . "\nProtocolo: " . $protocolo; + } + } + if ($this->std->ide->tpAmb === 2) { + //homologação + $message = "DOCUMENTO EMITIDO\nEM HOMOLOGAÇÃO"; + $submessage = "SEM VALOR FISCAL"; + } + $this->showMessage($message, $submessage); + } + + protected function waterMarkL() + { + $message = ''; + $submessage = ''; + $this->showMessage($message, $submessage); + } + + /** + * Exibe a marca d'água + * @param string $message + * @param string $submessage + * @return void + */ + protected function showMessage(string $message, string $submessage) + { + $y = $this->hPrint/2; + $h = 25; + $h1 = 15; + $this->pdf->settextcolor(200, 200, 200); + $aFont = ['font' => $this->fontePadrao, 'size' => 60, 'style' => 'B']; + $this->pdf->textBox($this->margesq, $y, $this->wPrint, $h, $message, $aFont, 'T', 'C', 0, ''); + $lines = $this->pdf->getNumLines($message, $this->wPrint, $aFont); + if ($lines > 1) { + $y = $y + $lines * $h1; + } else { + $y = $y + $h; + } + $h = 5; + $aFont = ['font' => $this->fontePadrao, 'size' => 40, 'style' => 'B']; + $this->pdf->textBox($this->margesq, $y, $this->wPrint, $h, $submessage, $aFont, 'C', 'C', 0, ''); + $this->pdf->settextcolor(0, 0, 0); + } +}