From f32c63d6ff9a814303d215d682dcfd86c6f0f027 Mon Sep 17 00:00:00 2001 From: Claudinei Pereira Jr Date: Thu, 1 Aug 2024 16:30:12 -0300 Subject: [PATCH] Added the New Services of Reverso (PAC, SEDEX, SEDEX10, etc) on Model\ServicoPostagem and Pdf\CartaoPostagem2018 --- src/PhpSigep/Model/ServicoDePostagem.php | 31 +++++-- src/PhpSigep/Pdf/CartaoDePostagem2018.php | 103 ++++++++++++++-------- 2 files changed, 88 insertions(+), 46 deletions(-) diff --git a/src/PhpSigep/Model/ServicoDePostagem.php b/src/PhpSigep/Model/ServicoDePostagem.php index 08b1016c4..b73c2f1ab 100644 --- a/src/PhpSigep/Model/ServicoDePostagem.php +++ b/src/PhpSigep/Model/ServicoDePostagem.php @@ -61,12 +61,20 @@ class ServicoDePostagem extends AbstractModel const SERVICE_SEDEX_CONTRATO_AGENCIA_TA = '04553'; const SERVICE_PAC_CONTRATO_AGENCIA_TA = '04596'; -// const SERVICE_CARTA_REGISTRADA = '10138'; + // const SERVICE_CARTA_REGISTRADA = '10138'; // NOVOS CODIGOS DE SERVICO DOS CORREIOS const SERVICE_PAC_CONTRATO_AGENCIA_03298 = '03298'; const SERVICE_SEDEX_CONTRATO_AGENCIA_03220 = '03220'; + // NOVOS CODIGO DE SERVICO REVERSO DOS CORREIOS 2024 + const SERVICE_PAC_REVERSO_03301 = '03301'; + const SERVICE_SEDEX_REVERSO_03247 = '03247'; + const SERVICE_SEDEX_10_REVERSO_03182 = '03182'; + const SERVICE_SEDEX_12_REVERSO_03174 = '03174'; + const SERVICE_SEDEX_HOJE_REVERSO_03190 = '03190'; + + // NOVOS CODIGOS DE SERVICO DOS CORREIOS BRONZE (1o sem 2020) const SERVICE_PAC_CONTRATO_AGENCIA_03085 = '03085'; const SERVICE_SEDEX_CONTRATO_AGENCIA_03050 = '03050'; @@ -81,6 +89,13 @@ class ServicoDePostagem extends AbstractModel self::SERVICE_PAC_CONTRATO_AGENCIA_03298 => array('Pac 03298', 162026), self::SERVICE_SEDEX_CONTRATO_AGENCIA_03220 => array('Sedex 03220', 162022), + // NOVOS CODIGOS DE SERVICO REVERSO DOS CORREIOS 2024 + self::SERVICE_PAC_REVERSO_03301 => array('Pac Reverso 03301', null), + self::SERVICE_SEDEX_REVERSO_03247 => array('Sedex Reverso 03247', null), + self::SERVICE_SEDEX_10_REVERSO_03182 => array('Sedex 10 Reverso 03182', null), + self::SERVICE_SEDEX_12_REVERSO_03174 => array('Sedex 12 Reverso 03174', null), + self::SERVICE_SEDEX_HOJE_REVERSO_03190 => array('Sedex Hoje Reverso 03190', null), + // NOVOS CODIGOS DE SERVICO DOS CORREIOS BRONZE (1o sem 2020) self::SERVICE_PAC_CONTRATO_AGENCIA_03085 => array('Pac 03085', 162011), self::SERVICE_SEDEX_CONTRATO_AGENCIA_03050 => array('Sedex 03050', 162008), @@ -199,17 +214,17 @@ public function __construct($serviceCode) ) ); } - /** - * @param array $arrayServicesCode - * array com os codigos de serviço - * - * @return ServicoDePostagem[] - */ + /** + * @param array $arrayServicesCode + * array com os codigos de serviço + * + * @return ServicoDePostagem[] + */ public static function getFromArray($arrayServicesCode) { $r = array(); foreach (self::$services as $serviceCode => $serviceDetails) { - if(array_key_exists($serviceCode,$arrayServicesCode)){ + if(array_key_exists($serviceCode, $arrayServicesCode)) { $r[] = new self($serviceCode); } } diff --git a/src/PhpSigep/Pdf/CartaoDePostagem2018.php b/src/PhpSigep/Pdf/CartaoDePostagem2018.php index ab46c21f7..b73bedb0d 100644 --- a/src/PhpSigep/Pdf/CartaoDePostagem2018.php +++ b/src/PhpSigep/Pdf/CartaoDePostagem2018.php @@ -65,10 +65,9 @@ public function render($dest='', $filename = '') header('Pragma: public'); echo $pdfContent; } else { - if($dest == 'S'){ + if($dest == 'S') { return $this->_render($dest, $filename); - } - else{ + } else { $this->_render($dest, $filename); Bootstrap::getConfig()->getCacheInstance()->setItem($cacheKey, $this->pdf->buffer); } @@ -80,7 +79,7 @@ public function render($dest='', $filename = '') * @param string $fileName * @return mixed */ - private function _render ($dest='', $fileName= '') + private function _render($dest='', $fileName= '') { $un = 72 / 25.4; $wFourAreas = $this->pdf->w; @@ -178,7 +177,7 @@ private function _render ($dest='', $fileName= '') case ServicoDePostagem::SERVICE_PAC_ADMINISTRATIVO: case ServicoDePostagem::SERVICE_PAC_04510: case ServicoDePostagem::SERVICE_PAC_GRANDES_FORMATOS: - case ServicoDePostagem::SERVICE_PAC_CONTRATO_GRANDES_FORMATOS; + case ServicoDePostagem::SERVICE_PAC_CONTRATO_GRANDES_FORMATOS: case ServicoDePostagem::SERVICE_PAC_CONTRATO_UO: case ServicoDePostagem::SERVICE_PAC_PAGAMENTO_NA_ENTREGA: case ServicoDePostagem::SERVICE_PAC_CONTRATO_AGENCIA: @@ -239,16 +238,33 @@ private function _render ($dest='', $fileName= '') $simbolo_de_encaminhamento = realpath(dirname(__FILE__)) . '/simbolo-sem-especificacao.png'; $_texto = 'Carta'; break; - case ServicoDePostagem::SERVICE_SEDEX_REVERSO: - $simbolo_de_encaminhamento = realpath(dirname(__FILE__)) . '/simbolo-sedex-standard.png'; - $_texto = 'SEDEX'; - break; case ServicoDePostagem::SERVICE_MINI_ENVIOS_04227: case ServicoDePostagem::SERVICE_MINI_ENVIOS_04235: case ServicoDePostagem::SERVICE_MINI_ENVIOS_04391: $simbolo_de_encaminhamento = realpath(dirname(__FILE__)) . '/simbolo-sem-especificacao.png'; $_texto = 'Mini Envios'; break; + case ServicoDePostagem::SERVICE_PAC_REVERSO_03301: + $chancela = new Pac2018(86, $this->pdf->GetY() + 13, $nomeRemetente, $accessData); + $_texto = 'PAC REVERSO'; + break; + case ServicoDePostagem::SERVICE_SEDEX_REVERSO: + case ServicoDePostagem::SERVICE_SEDEX_REVERSO_03247: + $simbolo_de_encaminhamento = realpath(dirname(__FILE__)) . '/simbolo-sedex-standard.png'; + $_texto = 'SEDEX REVERSO'; + break; + case ServicoDePostagem::SERVICE_SEDEX_10_REVERSO_03182: + $simbolo_de_encaminhamento = realpath(dirname(__FILE__)) . '/simbolo-sedex-expresso.png'; + $_texto = 'SEDEX 10 REVERSO'; + break; + case ServicoDePostagem::SERVICE_SEDEX_12_REVERSO_03174: + $simbolo_de_encaminhamento = realpath(dirname(__FILE__)) . '/simbolo-sedex-expresso.png'; + $_texto = 'SEDEX 12 REVERSO'; + break; + case ServicoDePostagem::SERVICE_SEDEX_HOJE_REVERSO_03190: + $simbolo_de_encaminhamento = realpath(dirname(__FILE__)) . '/simbolo-sedex-expresso.png'; + $_texto = 'SEDEX Hoje REVERSO'; + break; default: $simbolo_de_encaminhamento = null; break; @@ -256,7 +272,7 @@ private function _render ($dest='', $fileName= '') if ($simbolo_de_encaminhamento) { $this->pdf->Image($simbolo_de_encaminhamento, 81, $this->pdf->GetY() + 2, 20, 20); - } else if ($chancela) { + } elseif ($chancela) { $chancela->draw($this->pdf); } @@ -266,8 +282,8 @@ private function _render ($dest='', $fileName= '') $this->pdf->SetFontSize(9); //$this->pdf->SetTextColor(51,51,51); $nf = $objetoPostal->getDestino()->getNumeroNotaFiscal(); - $str = $nf > 0 ? 'NF: '. substr($nf,5) : ' '; - $this->t(15, $str, 1, 'L', null); + $str = $nf > 0 ? 'NF: '. substr($nf, 5) : ' '; + $this->t(15, $str, 1, 'L', null); // Contrato $AccessData = $this->plp->getAccessData(); @@ -346,22 +362,22 @@ private function _render ($dest='', $fileName= '') if ($servicoAdicional->is(ServicoAdicional::SERVICE_AVISO_DE_RECEBIMENTO)) { $sSer = $sSer . "01"; $_siglaAdicinal[] = "AR"; - } else if ($servicoAdicional->is(ServicoAdicional::SERVICE_MAO_PROPRIA)) { + } elseif ($servicoAdicional->is(ServicoAdicional::SERVICE_MAO_PROPRIA)) { $sSer = $sSer . "02"; $_siglaAdicinal[] = "MP"; - } else if ($servicoAdicional->is(ServicoAdicional::SERVICE_VALOR_DECLARADO_SEDEX)) { + } elseif ($servicoAdicional->is(ServicoAdicional::SERVICE_VALOR_DECLARADO_SEDEX)) { $sSer = $sSer . "19"; $_siglaAdicinal[] = "VD"; $valorDeclarado = $servicoAdicional->getValorDeclarado(); - } else if ($servicoAdicional->is(ServicoAdicional::SERVICE_VALOR_DECLARADO_PAC)) { + } elseif ($servicoAdicional->is(ServicoAdicional::SERVICE_VALOR_DECLARADO_PAC)) { $sSer = $sSer . "64"; $_siglaAdicinal[] = "VD"; $valorDeclarado = $servicoAdicional->getValorDeclarado(); - } else if ($servicoAdicional->is(ServicoAdicional::SERVICE_VALOR_DECLARADO_MINI_ENVIOS)) { + } elseif ($servicoAdicional->is(ServicoAdicional::SERVICE_VALOR_DECLARADO_MINI_ENVIOS)) { $sSer = $sSer . "65"; $_siglaAdicinal[] = "VD"; $valorDeclarado = $servicoAdicional->getValorDeclarado(); - } else if ($servicoAdicional->is(ServicoAdicional::SERVICE_REGISTRO)) { + } elseif ($servicoAdicional->is(ServicoAdicional::SERVICE_REGISTRO)) { $sSer = $sSer . "25"; } } @@ -374,10 +390,10 @@ private function _render ($dest='', $fileName= '') foreach ($_siglaAdicinal as $_key => $_sigla) { if ($_ctadc > 1 && $_ctadc <= 4) { $_hupdate += 5; - } else if ($_ctadc == 5) { + } elseif ($_ctadc == 5) { $_hupdate = $_hinit; $_winit = 98; - } else if ($_ctadc >= 6) { + } elseif ($_ctadc >= 6) { $_hupdate += 5; } @@ -456,7 +472,7 @@ private function _render ($dest='', $fileName= '') $objetoPostal->getServicoDePostagem()->getCodigo(), $valorDeclarado, $objetoPostal->getDestinatario()->getTelefone() - // $objetoPostal->getDestinatario()->getComplemento() + // $objetoPostal->getDestinatario()->getComplemento() ); require_once 'Semacode.php'; @@ -471,7 +487,7 @@ private function _render ($dest='', $fileName= '') $this->writeRemetente(0, $currentY + $hCepBarCode + 4, $wAddressLeftCol, $this->plp->getRemetente()); $this->pdf->SetXY(0, 0); - $this->pdf->SetDrawColor(0,0,0); + $this->pdf->SetDrawColor(0, 0, 0); $this->pdf->Rect(0, 0, 106.36, 140); } @@ -508,7 +524,7 @@ private function init() * @internal param $lineHeigth * @internal param \Sigep\Cliente $destinatario */ - private function writeDestinatario ($l, $t, $w, $objetoPostal) + private function writeDestinatario($l, $t, $w, $objetoPostal) { $l = $this->pdf->GetX(); $t1 = $this->pdf->GetY(); @@ -557,7 +573,7 @@ private function writeDestinatario ($l, $t, $w, $objetoPostal) return $t; } - private function writeRemetente ($l, $t, $w, \PhpSigep\Model\Remetente $remetente) + private function writeRemetente($l, $t, $w, \PhpSigep\Model\Remetente $remetente) { $titulo = 'Remetente:'; $nomeDestinatario = $remetente->getNome(); @@ -604,30 +620,41 @@ private function writeRemetente ($l, $t, $w, \PhpSigep\Model\Remetente $remetent * @internal param $lineHeigth * @internal param $objetoPostal */ - private function writeEndereco ( - $t, $l, $w, $titulo, $nomeDestinatario, $logradouro, $numero1, $complemento, $bairro, - $cidade, $uf, $cep = null, $destinatario = false + private function writeEndereco( + $t, + $l, + $w, + $titulo, + $nomeDestinatario, + $logradouro, + $numero1, + $complemento, + $bairro, + $cidade, + $uf, + $cep = null, + $destinatario = false ) { //$this->pdf->SetTextColor(51,51,51); if ($destinatario === true) { $addressPadding = 5; $t = $t-2; - $this->pdf->SetDrawColor(0,0,0); + $this->pdf->SetDrawColor(0, 0, 0); $this->pdf->Line(0, $t, 106.36, $t); // Titulo do bloco: destinatario - $this->pdf->setFillColor(0,0,0); - $this->pdf->SetDrawColor(0,0,0); + $this->pdf->setFillColor(0, 0, 0); + $this->pdf->SetDrawColor(0, 0, 0); $this->pdf->Rect(0, $t, 36, 5, 'F'); $this->pdf->SetFont('', 'B'); $this->pdf->SetFontSize(11); - $this->pdf->SetTextColor(255,255,255); + $this->pdf->SetTextColor(255, 255, 255); $this->pdf->SetXY($l + 3, $t); $this->t($w, $titulo, 2, ''); - $this->pdf->SetTextColor(0,0,0); + $this->pdf->SetTextColor(0, 0, 0); $this->pdf->Image(realpath(dirname(__FILE__)) . '/logo-correios.png', 84, $t+1, 20, 4); @@ -640,7 +667,7 @@ private function writeEndereco ( } else { $addressPadding = 2; $t = $t -1; - $this->pdf->SetDrawColor(0,0,0); + $this->pdf->SetDrawColor(0, 0, 0); $this->pdf->Line(0, $t, 106.36, $t); $t++; @@ -695,12 +722,12 @@ private function writeEndereco ( return $this->pdf->GetY(); } - private function setFillColor ($r, $g, $b) + private function setFillColor($r, $g, $b) { - $this->pdf->SetFillColor ($r, $g, $b); + $this->pdf->SetFillColor($r, $g, $b); } - private function t ($w, $txt, $ln, $align, $h = null, $multiLines = false, $utf8 = true) + private function t($w, $txt, $ln, $align, $h = null, $multiLines = false, $utf8 = true) { if ($utf8) { $txt = $this->_($txt); @@ -720,12 +747,12 @@ private function t ($w, $txt, $ln, $align, $h = null, $multiLines = false, $utf8 } } - private function multiLines ($w, $txt, $align, $h = null, $utf8 = true) + private function multiLines($w, $txt, $align, $h = null, $utf8 = true) { $this->t($w, $txt, null, $align, $h, true, $utf8); } - private function CalcDigCep ($cep) + private function CalcDigCep($cep) { $str = str_split($cep); $sum = 0; @@ -737,7 +764,7 @@ private function CalcDigCep ($cep) return $digCep; } - private function getM2Dstr ($cepD, $numD, $cepO, $numO, $etq, $srvA, $carP, $codS, $valD, $telD, $msg='') + private function getM2Dstr($cepD, $numD, $cepO, $numO, $etq, $srvA, $carP, $codS, $valD, $telD, $msg='') { $str = ''; $str .= str_replace('-', '', $cepD);