PhpSigep\Pdf\CartaoDePostagem2016::_render PHP Method

_render() private method

private _render ( string $dest = '', string $fileName = '' ) : mixed
$dest string
$fileName string
return mixed
    private function _render($dest = '', $fileName = '')
    {
        $un = 72 / 25.4;
        $wFourAreas = $this->pdf->w;
        $hFourAreas = $this->pdf->h;
        //-Menos 1.5CM porque algumas impressoras não conseguem imprimir nos ultimos 1cm da página
        $tMarginFourAreas = 0;
        $rMarginFourAreas = 0;
        $bMarginFourAreas = 0;
        $lMarginFourAreas = 0;
        $wInnerFourAreas = $wFourAreas - $lMarginFourAreas - $rMarginFourAreas;
        $hInnerFourAreas = 0;
        $margins = array(array('l' => $lMarginFourAreas, 'r' => $wFourAreas - $rMarginFourAreas, 't' => $tMarginFourAreas, 'b' => $hFourAreas - $bMarginFourAreas), array('l' => $wFourAreas + $lMarginFourAreas, 'r' => $wFourAreas * 2 - $rMarginFourAreas, 't' => $tMarginFourAreas, 'b' => $hFourAreas - $bMarginFourAreas), array('l' => $lMarginFourAreas, 'r' => $wFourAreas - $rMarginFourAreas, 't' => $hFourAreas + $tMarginFourAreas, 'b' => $hFourAreas * 2 - $bMarginFourAreas), array('l' => $wFourAreas + $lMarginFourAreas, 'r' => $wFourAreas * 2 - $rMarginFourAreas, 't' => $hFourAreas + $tMarginFourAreas, 'b' => $hFourAreas * 2 - $bMarginFourAreas));
        $objetosPostais = $this->plp->getEncomendas();
        $total = count($objetosPostais);
        while (count($objetosPostais)) {
            $this->pdf->AddPage();
            if (Bootstrap::getConfig()->getSimular()) {
                $this->pdf->SetFont('Arial', 'B', 50);
                $this->pdf->SetTextColor(240, 240, 240);
                $this->pdf->SetXY($lMarginFourAreas, $hFourAreas - $this->pdf->getLineHeigth());
                $this->pdf->MultiCellXp($this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin, "Simulação Documento sem valor", null, 0, 'C');
                $this->pdf->SetXY($lMarginFourAreas, $margins[2]['t'] + $hFourAreas - $this->pdf->getLineHeigth());
                $this->pdf->MultiCellXp($this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin, "Simulação Documento sem valor", null, 0, 'C');
                $this->pdf->SetTextColor(0, 0, 0);
            }
            $this->pdf->SetDrawColor(0, 0, 0);
            for ($area = 0; $area < 1; $area++) {
                if (!count($objetosPostais)) {
                    break;
                }
                /** @var $objetoPostal ObjetoPostal */
                $objetoPostal = array_shift($objetosPostais);
                $lPosFourAreas = $margins[$area]['l'];
                $rPosFourAreas = $margins[$area]['r'];
                $tPosFourAreas = $margins[$area]['t'];
                $bPosFourAreas = $margins[$area]['b'];
                // Logo
                $this->pdf->SetXY($lPosFourAreas, $tPosFourAreas);
                $this->setFillColor(222, 222, 222);
                $headerColWidth = $wInnerFourAreas / 3;
                $headerHeigth = 106;
                if ($this->logoFile) {
                    $this->pdf->Image($this->logoFile, 66, $this->pdf->GetY() + 3, 25);
                }
                // Chancela
                //$this->pdf->SetXY(66, 3, 0);
                $this->setFillColor(150, 150, 200);
                //Nao utilizados
                //$wChancela = 101.5;
                //$hChancela = 72.5;
                $lPosChancela = 3;
                $tPosChancela = 1;
                $servicoDePostagem = $objetoPostal->getServicoDePostagem();
                $nomeRemetente = $this->plp->getRemetente()->getNome();
                $accessData = $this->plp->getAccessData();
                switch ($servicoDePostagem->getCodigo()) {
                    case ServicoDePostagem::SERVICE_PAC_41068:
                    case ServicoDePostagem::SERVICE_PAC_41106:
                    case ServicoDePostagem::SERVICE_PAC_GRANDES_FORMATOS:
                        if ($this->layoutPac === CartaoDePostagem::TYPE_CHANCELA_PAC) {
                            $chancela = new Pac($lPosChancela, $tPosChancela, $nomeRemetente, $accessData);
                        } else {
                            $chancela = new Pac2016($lPosChancela, $tPosChancela, $nomeRemetente, $accessData);
                        }
                        break;
                    case ServicoDePostagem::SERVICE_E_SEDEX_STANDARD:
                        $tPosChancela = 3;
                        if ($this->layoutSedex === CartaoDePostagem::TYPE_CHANCELA_SEDEX) {
                            $chancela = new Sedex($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_E_SEDEX, $accessData);
                        } else {
                            $chancela = new Sedex2016($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_E_SEDEX, $accessData);
                        }
                        break;
                    case ServicoDePostagem::SERVICE_SEDEX_40096:
                    case ServicoDePostagem::SERVICE_SEDEX_40436:
                    case ServicoDePostagem::SERVICE_SEDEX_40444:
                    case ServicoDePostagem::SERVICE_SEDEX_A_VISTA:
                    case ServicoDePostagem::SERVICE_SEDEX_VAREJO_A_COBRAR:
                    case ServicoDePostagem::SERVICE_SEDEX_PAGAMENTO_NA_ENTREGA:
                    case ServicoDePostagem::SERVICE_SEDEX_AGRUPADO:
                        $tPosChancela = 3;
                        if ($this->layoutSedex === CartaoDePostagem::TYPE_CHANCELA_SEDEX) {
                            $chancela = new Sedex($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX, $accessData);
                        } else {
                            $chancela = new Sedex2016($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX, $accessData);
                        }
                        break;
                    case ServicoDePostagem::SERVICE_SEDEX_12:
                        $tPosChancela = 3;
                        if ($this->layoutSedex === CartaoDePostagem::TYPE_CHANCELA_SEDEX) {
                            $chancela = new Sedex($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX_12, $accessData);
                        } else {
                            $chancela = new Sedex2016($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX_12, $accessData);
                        }
                        break;
                    case ServicoDePostagem::SERVICE_SEDEX_10:
                    case ServicoDePostagem::SERVICE_SEDEX_10_PACOTE:
                        $tPosChancela = 3;
                        if ($this->layoutSedex === CartaoDePostagem::TYPE_CHANCELA_SEDEX) {
                            $chancela = new Sedex($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX_10, $accessData);
                        } else {
                            $chancela = new Sedex2016($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX_10, $accessData);
                        }
                        break;
                    case ServicoDePostagem::SERVICE_SEDEX_HOJE_40290:
                    case ServicoDePostagem::SERVICE_SEDEX_HOJE_40878:
                        $tPosChancela = 3;
                        if ($this->layoutSedex === CartaoDePostagem::TYPE_CHANCELA_SEDEX) {
                            $chancela = new Sedex($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX_HOJE, $accessData);
                        } else {
                            $chancela = new Sedex2016($lPosChancela, $tPosChancela, $nomeRemetente, Sedex::SERVICE_SEDEX_HOJE, $accessData);
                        }
                        break;
                    case ServicoDePostagem::SERVICE_CARTA_COMERCIAL_A_FATURAR:
                    case ServicoDePostagem::SERVICE_CARTA_REGISTRADA:
                        if ($this->layoutCarta === CartaoDePostagem::TYPE_CHANCELA_CARTA) {
                            $chancela = new Carta($lPosChancela, $tPosChancela, $nomeRemetente, $accessData);
                        } else {
                            $chancela = new Carta2016($lPosChancela, $tPosChancela, $nomeRemetente, $accessData);
                        }
                        break;
                    case ServicoDePostagem::SERVICE_SEDEX_REVERSO:
                    default:
                        $chancela = null;
                        break;
                }
                if ($chancela) {
                    $chancela->draw($this->pdf);
                }
                // Volume
                $this->setFillColor(100, 150, 200);
                $this->pdf->SetXY(0, 25);
                $nf = (int) $objetoPostal->getDestino()->getNumeroNotaFiscal();
                $str = $nf > 0 ? '      NF: ' . $nf : '               ';
                $this->pdf->SetFontSize(8);
                $this->t(15, $str, 1, 'L', null);
                $this->pdf->SetXY(35, 25);
                $this->t(15, '   PLP: ' . $this->idPlpCorreios, 1, 'C', null);
                $this->pdf->SetXY(70, 25);
                $this->t(15, '   Peso(g): ' . round($objetoPostal->getPeso() * 1000), 1, 'R', null);
                // Número da etiqueta
                $this->setFillColor(100, 100, 200);
                $this->pdf->SetXY(0, $this->pdf->GetY() + 1);
                $this->pdf->SetFontSize(9);
                $this->pdf->SetFont('', 'B');
                $etiquetaComDv = $objetoPostal->getEtiqueta()->getEtiquetaComDv();
                $this->t($wInnerFourAreas, $etiquetaComDv, 1, 'C');
                // Código de barras da etiqueta
                $this->setFillColor(0, 0, 0);
                $tPosEtiquetaBarCode = $this->pdf->GetY();
                $hEtiquetaBarCode = 22;
                $wEtiquetaBarCode = 78;
                $code128 = new \PhpSigep\Pdf\Script\BarCode128();
                $code128->draw($this->pdf, ($this->pdf->w - $wEtiquetaBarCode) / 2, $tPosEtiquetaBarCode, $etiquetaComDv, $wEtiquetaBarCode, $hEtiquetaBarCode);
                // Nome legivel, doc e rubrica
                $this->pdf->SetFontSize(7);
                $this->pdf->SetXY(1, $this->pdf->GetY() + 24);
                $this->t(0, 'Nome Legível:___________________________________________', 1, 'L', null);
                $this->pdf->SetXY(1, $this->pdf->GetY() + 1);
                $this->t(0, 'Documento:______________________________________________', 1, 'L', null);
                // Destinatário
                $wAddressLeftCol = $this->pdf->w - 5;
                $tPosAfterNameBlock = 71;
                $destinatario = $objetoPostal->getDestinatario();
                $t = $this->writeDestinatario($lPosFourAreas, $tPosAfterNameBlock, $wAddressLeftCol, $objetoPostal);
                $destino = $objetoPostal->getDestino();
                // Número do CEP
                $cep = $destino->getCep();
                $cep = preg_replace('/[^\\d]/', '', $cep);
                $tPosCepBarCode = $t + 1;
                // Etiqueta do CEP
                $hCepBarCode = 22;
                $wCepBarCode = 47;
                $this->setFillColor(0, 0, 0);
                $code128 = new \PhpSigep\Pdf\Script\BarCode128();
                $code128->draw($this->pdf, 6, $tPosCepBarCode, $cep, $wCepBarCode, $hCepBarCode);
                $valorDeclarado = null;
                $sSer = "";
                foreach ($objetoPostal->getServicosAdicionais() as $servicoAdicional) {
                    if ($servicoAdicional->is(ServicoAdicional::SERVICE_AVISO_DE_RECEBIMENTO)) {
                        $temAr = true;
                        $sSer = $sSer . "01";
                    } else {
                        if ($servicoAdicional->is(ServicoAdicional::SERVICE_MAO_PROPRIA)) {
                            $temMp = true;
                            $sSer = $sSer . "02";
                        } else {
                            if ($servicoAdicional->is(ServicoAdicional::SERVICE_VALOR_DECLARADO)) {
                                $temVd = true;
                                $sSer = $sSer . "19";
                                $valorDeclarado = $servicoAdicional->getValorDeclarado();
                            } else {
                                if ($servicoAdicional->is(ServicoAdicional::SERVICE_REGISTRO)) {
                                    $temRe = true;
                                    $sSer = $sSer . "25";
                                }
                            }
                        }
                    }
                }
                while (strlen($sSer) < 12) {
                    $sSer = $sSer . "00";
                }
                $sM2Dtext = $this->getM2Dstr($cep, $objetoPostal->getDestinatario()->getNumero(), $this->plp->getRemetente()->getCep(), $this->plp->getRemetente()->getNumero(), $etiquetaComDv, $sSer, $this->plp->getAccessData()->getCartaoPostagem(), $objetoPostal->getServicoDePostagem()->getCodigo(), $valorDeclarado, $objetoPostal->getDestinatario()->getTelefone());
                require_once 'Semacode.php';
                $semacode = new \Semacode();
                $semaCodeGD = $semacode->asGDImage($sM2Dtext);
                $this->setFillColor(222, 222, 222);
                $this->pdf->gdImage($semaCodeGD, 40, 0, 25);
                imagedestroy($semaCodeGD);
            }
            $this->writeRemetente(0, $this->pdf->GetY() + $hCepBarCode + 5, $wAddressLeftCol, $this->plp->getRemetente());
        }
        return $this->pdf->Output($fileName, $dest);
    }