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);
}
// $crossMargin = 50;
// $this->pdf->SetDrawColor(200, 200, 200);
// for ($lineY = $crossMargin; $lineY < $this->pdf->h - $crossMargin; $lineY += 10) {
// $this->pdf->Line($wFourAreas, $lineY, $wFourAreas, $lineY + 3);
// }
// for ($lineX = $crossMargin; $lineX < $this->pdf->w - $crossMargin; $lineX += 10) {
// $this->pdf->Line($lineX, $hFourAreas, $lineX + 3, $hFourAreas);
// }
$this->pdf->SetDrawColor(0, 0, 0);
for ($area = 0; $area < 1; $area++) {
if (!count($objetosPostais)) {
break;
}
/** @var $objetoPostal \PhpSigep\Model\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, 3, 0, 25);
}
// Chancela
$this->pdf->SetXY(66, $this->pdf->GetY() + 3);
$this->setFillColor(150, 150, 200);
$wChancela = 101.5;
$hChancela = 72.5;
$lPosChancela = 66;
$tPosChancela = $this->pdf->GetY();
$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:
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:
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:
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:
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:
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);
}
// Título da etiqueta
if ($this->idPlpCorreios > 0) {
$lPosHeaderCol2 = $headerColWidth + $lPosFourAreas;
// $this->pdf->SetXY($lPosHeaderCol2, $tPosFourAreas);
// $this->setFillColor(200, 200, 200);
// $this->pdf->SetFontSize(12);
// $this->pdf->SetFont('', 'B');
// $this->t($headerColWidth, 'Cartão de Postagem', 2, 'C');
// Número da plp
$this->pdf->SetXY($lPosHeaderCol2, $tPosFourAreas + 32);
$this->setFillColor(150, 200, 200);
$this->pdf->SetFont('', '');
$this->pdf->SetFontSize(9);
$this->t($headerColWidth * 3, 'PLP: ' . $this->idPlpCorreios, 0, 'C');
}
// Volume
$this->setFillColor(100, 150, 200);
$this->pdf->SetXY(0, 30);
$nf = (double) $objetoPostal->getDestino()->getNumeroNotaFiscal();
if ($nf > 0) {
$nf = ' NF: ' . $nf;
}
$numeroPedido = trim($objetoPostal->getDestino()->getNumeroPedido());
if (!empty($numeroPedido)) {
$numeroPedido = ' Pedido: ' . $numeroPedido;
}
$this->pdf->SetFontSize(7);
$this->t($this->pdf->w, 'Volume: 1/1 ' . 'Peso(kg): ' . (double) $objetoPostal->getPeso() . $nf . $numeroPedido, 1, 'C', 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() + 23);
$this->t(0, 'Nome Legível:___________________________________________', 1, 'L', null);
$this->pdf->SetXY(1, $this->pdf->GetY() + 1);
$this->t(0, 'Documento:_______________________Rubrica:_____________________', 1, 'L', null);
// Destinatário
$wAddressLeftCol = $this->pdf->w - 5;
$tPosAfterNameBlock = 71;
$t = $this->writeDestinatario($lPosFourAreas, $tPosAfterNameBlock, $wAddressLeftCol, $objetoPostal);
$destino = $objetoPostal->getDestino();
if ($destino instanceof \PhpSigep\Model\DestinoNacional) {
// 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->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, 35, 3, 25);
imagedestroy($semaCodeGD);
}
$this->writeRemetente(0, $this->pdf->GetY() + $hCepBarCode + 5, $wAddressLeftCol, $this->plp->getRemetente());
}
}
if ($dest == 'S') {
return $this->pdf->Output($filename, $dest);
} else {
$this->pdf->Output($filename, $dest);
}
}