protected function gerarCodigoBarras()
{
if ($this->tipo == self::CEF_TIPO_POS11) {
$this->codigoBarras = $this->getBanco();
$this->codigoBarras .= $this->numeroMoeda;
$this->codigoBarras .= Util::fatorVencimento($this->getDataVencimento());
$this->codigoBarras .= Util::numberFormatValue($this->getValor(), 10, 0);
$this->codigoBarras .= $this->gerarNossoNumero();
$this->codigoBarras .= Util::numberFormatGeral($this->getAgencia(), 4, 0);
$this->codigoBarras .= Util::numberFormatGeral($this->cedenteCodigo, 11, 0);
} else {
if ($this->tipo == self::CEF_TIPO_POS16) {
$this->codigoBarras = $this->getBanco();
$this->codigoBarras .= $this->numeroMoeda;
$this->codigoBarras .= Util::fatorVencimento($this->getDataVencimento());
$this->codigoBarras .= Util::numberFormatValue($this->getValor(), 10, 0);
$this->codigoBarras .= substr($this->cedenteCodigo, -5);
$this->codigoBarras .= $this->getAgencia();
$this->codigoBarras .= 87;
$this->codigoBarras .= $this->gerarNossoNumero();
} else {
throw new Exception("Tipo do bloqueto inválido");
}
}
$r = Util::modulo11($this->codigoBarras, 9, 1);
$dv = $r == 0 || $r == 1 || $r == 10 ? 1 : 11 - $r;
$this->codigoBarras = substr($this->codigoBarras, 0, 4) . $dv . substr($this->codigoBarras, 4);
$this->carteira = $this->carteiraDesc[$this->getCarteira()];
return $this->codigoBarras;
}