Skip to content

Commit

Permalink
Merge pull request stavarengo#114 from dehdocs/php7-fix
Browse files Browse the repository at this point in the history
Alteração na classe Semacode
  • Loading branch information
stavarengo authored Mar 24, 2017
2 parents 38ef0a0 + 6062794 commit f4f4ff1
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 20 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"require": {
"php": ">=5.4",
"stavarengo/php-sigep-fpdf": "dev-master"
"stavarengo/php-sigep-fpdf": "dev-master",
"setasign/fpdi": "1.6.1"
},
"autoload": {
"psr-0": {
Expand Down
55 changes: 52 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added exemplos/etiquetas.pdf
Binary file not shown.
68 changes: 68 additions & 0 deletions exemplos/helper-criar-pre-lista-a4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Este script cria e retorna uma instância de {@link \PhpSigep\Model\PreListaDePostagem}
*
* Como existe mais de um exemplo que precisa de uma {@link \PhpSigep\Model\PreListaDePostagem}, esse script foi criado
* para compartilhar o código necessário para a criação da {@link \PhpSigep\Model\PreListaDePostagem}.
*/


// *** DADOS DA ENCOMENDA QUE SERÁ DESPACHADA *** //
$dimensao = new \PhpSigep\Model\Dimensao();
$dimensao->setAltura(20);
$dimensao->setLargura(20);
$dimensao->setComprimento(20);
$dimensao->setDiametro(0);
$dimensao->setTipo(\PhpSigep\Model\Dimensao::TIPO_PACOTE_CAIXA);

$destinatario = new \PhpSigep\Model\Destinatario();
$destinatario->setNome('Google Belo Horizonte');
$destinatario->setLogradouro('Av. Bias Fortes');
$destinatario->setNumero('382');
$destinatario->setComplemento('6º andar');

$destino = new \PhpSigep\Model\DestinoNacional();
$destino->setBairro('Lourdes');
$destino->setCep('30170-010');
$destino->setCidade('Belo Horizonte');
$destino->setUf('MG');

// Estamos criando uma etique falsa, mas em um ambiente real voçê deve usar o método
// {@link \PhpSigep\Services\SoapClient\Real::solicitaEtiquetas() } para gerar o número das etiquetas
$etiqueta = new \PhpSigep\Model\Etiqueta();
$etiqueta->setEtiquetaSemDv('PD73958096BR');

$servicoAdicional = new \PhpSigep\Model\ServicoAdicional();
$servicoAdicional->setCodigoServicoAdicional(\PhpSigep\Model\ServicoAdicional::SERVICE_REGISTRO);
// Se não tiver valor declarado informar 0 (zero)
$servicoAdicional->setValorDeclarado(0);

$encomenda = new \PhpSigep\Model\ObjetoPostal();
$encomenda->setServicosAdicionais(array($servicoAdicional));
$encomenda->setDestinatario($destinatario);
$encomenda->setDestino($destino);
$encomenda->setDimensao($dimensao);
$encomenda->setEtiqueta($etiqueta);
$encomenda->setPeso(0.500);// 500 gramas
$encomenda->setServicoDePostagem(new \PhpSigep\Model\ServicoDePostagem(\PhpSigep\Model\ServicoDePostagem::SERVICE_SEDEX_40096));
// *** FIM DOS DADOS DA ENCOMENDA QUE SERÁ DESPACHADA *** //

// *** DADOS DO REMETENTE *** //
$remetente = new \PhpSigep\Model\Remetente();
$remetente->setNome('Google São Paulo');
$remetente->setLogradouro('Av. Brigadeiro Faria Lima');
$remetente->setNumero('3900');
$remetente->setComplemento('5º andar');
$remetente->setBairro('Itaim');
$remetente->setCep('04538-132');
$remetente->setUf('SP');
$remetente->setCidade('São Paulo');
// *** FIM DOS DADOS DO REMETENTE *** //


$plp = new \PhpSigep\Model\PreListaDePostagem();
$plp->setAccessData(new \PhpSigep\Model\AccessDataHomologacao());
$plp->setEncomendas([$encomenda,$encomenda,$encomenda,$encomenda]);
$plp->setRemetente($remetente);

return $plp;
2 changes: 1 addition & 1 deletion exemplos/imprimirEtiquetas2016.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once __DIR__ . '/bootstrap-exemplos.php';

$params = include __DIR__ . '/helper-criar-pre-lista.php';
$params = include __DIR__ . '/helper-criar-pre-lista-a4.php';

// Logo da empresa remetente
$logoFile = __DIR__ . '/logo-etiqueta-2016.png';
Expand Down
56 changes: 56 additions & 0 deletions exemplos/imprimirEtiquetasA4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
require_once __DIR__ . '/bootstrap-exemplos.php';

$params = include __DIR__ . '/helper-criar-pre-lista-a4.php';

// Logo da empresa remetente
$logoFile = __DIR__ . '/logo-etiqueta-2016.png';

//Parametro opcional indica qual layout utilizar para a chancela. Ex.: CartaoDePostagem::TYPE_CHANCELA_CARTA, CartaoDePostagem::TYPE_CHANCELA_CARTA_2016
$layoutChancela = array(); //array(\PhpSigep\Pdf\CartaoDePostagem2016::TYPE_CHANCELA_SEDEX_2016);

$pdf = new \PhpSigep\Pdf\CartaoDePostagem2016($params, time(), $logoFile, $layoutChancela);

$fileName = 'etiquetas.pdf';
$pdf->render('F',$fileName);

unset($pdf);
$pdf = new \PhpSigep\PDF\ImprovedFPDF('P', 'mm', 'Letter' );
$pageCount = $pdf->setSourceFile($fileName);

$pdf->AddPage();
$pdf->SetFillColor(0,0,0);
$pdf->SetFont('Arial','B',16);

for($i=1;$i<=$pageCount;$i++) {
$tplIdx = $pdf->importPage($i, '/MediaBox');

$mod = $i % 4;

switch ($mod) {
case 0:
//A4: 210(x) × 297(y)
//Letter: 216 (x) × 279 (y)
$pdf->useTemplate($tplIdx, 110, 145, 105, 138, true);

if ($i !== $pageCount) {
$pdf->AddPage();
$pdf->SetFillColor(0,0,0);
$pdf->SetFont('Arial','B',16);
}
break;
case 1:
$pdf->useTemplate($tplIdx, 10, 10, 105, 138, true);
break;
case 2:
$pdf->useTemplate($tplIdx, 110, 10, 105, 138, true);
break;
case 3:
$pdf->useTemplate($tplIdx, 10, 145, 105, 138, true);
break;
}

}


$pdf->Output();
26 changes: 13 additions & 13 deletions src/PhpSigep/Pdf/ImprovedFPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author: Stavarengo
* @modify Anderson Luiz Silvério <andersonlsilverio@gmail.com>
*/
class ImprovedFPDF extends \PhpSigepFPDF
class ImprovedFPDF extends \FPDI
{
/**
* @var int
Expand All @@ -21,7 +21,7 @@ class ImprovedFPDF extends \PhpSigepFPDF

private $widths;
private $aligns;

function __construct($orientation = 'P', $unit = 'mm', $size = 'A4')
{
parent::__construct($orientation, $unit, $size);
Expand All @@ -33,7 +33,7 @@ function __construct($orientation = 'P', $unit = 'mm', $size = 'A4')
stream_wrapper_register("var", '\PhpSigep\Pdf\VariableStream') or die("Failed to register protocol");
//stream_wrapper_unregister("var");
}

}

public function _($str)
Expand Down Expand Up @@ -210,27 +210,27 @@ function _putcatalog() {
$this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>');
}
}

function SetDash($black=null, $white=null) {
if($black!==null)
$s=sprintf('[%.3F %.3F] 0 d',$black*$this->k,$white*$this->k);
else
$s='[] 0 d';
$this->_out($s);
}

function SetWidths($w)
{
//Set the array of column widths
$this->widths=$w;
}

function SetAligns($a)
{
//Set the array of column alignments
$this->aligns=$a;
}

function Row($data)
{
//Calculate the height of the row
Expand Down Expand Up @@ -259,14 +259,14 @@ function Row($data)
//Go to the next line
$this->Ln($h);
}

function CheckPageBreak($h)
{
//If the height h would cause an overflow, add a new page immediately
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}

function NbLines($w,$txt)
{
//Computes the number of lines a MultiCell of width w will take
Expand Down Expand Up @@ -320,7 +320,7 @@ function NbLines($w,$txt)
}
return $nl;
}

function RoundedRect($x, $y, $w, $h, $r, $corners = '1234', $style = '')
{
$k = $this->k;
Expand All @@ -333,7 +333,7 @@ function RoundedRect($x, $y, $w, $h, $r, $corners = '1234', $style = '')
$op='S';
$MyArc = 4/3 * (sqrt(2) - 1);
$this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));

$xc = $x+$w-$r;
$yc = $y+$r;
$this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));
Expand Down Expand Up @@ -370,14 +370,14 @@ function RoundedRect($x, $y, $w, $h, $r, $corners = '1234', $style = '')
$this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
$this->_out($op);
}

function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
{
$h = $this->h;
$this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
$x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
}

}

//Stream handler to read from global variables
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSigep/Pdf/Semacode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ReedSolomon {
var $rslen = 0;


function ReedSolomon($blockSize) {
function __construct($blockSize) {
// galois field polynomial for ECC 200
$this->initializeGaloisField(0x12d);
// index is 1 for ECC 200
Expand Down Expand Up @@ -167,7 +167,7 @@ class Semacode {
var $codings = "ACTXEB";
var $debug = false;

function Semacode() {
function __construct() {
$this->Encodings = array(
$this->makeEncoding(10, 10, 10, 10, 3, 3, 5),
$this->makeEncoding(12, 12, 12, 12, 5, 5, 7),
Expand Down

0 comments on commit f4f4ff1

Please sign in to comment.