protected function gerarCodigoBarras()
{
if ($this->getCarteira() == 'cnr') {
$this->agenciaConta = sprintf('%s %s', $this->getAgencia(), $this->cedenteCodigo);
$this->codigoBarras = $this->getBanco();
$this->codigoBarras .= $this->numeroMoeda;
$this->codigoBarras .= Util::fatorVencimento($this->getDataVencimento());
$this->codigoBarras .= Util::numberFormatValue($this->getValor(), 10, 0);
$this->codigoBarras .= Util::numberFormatGeral($this->cedenteCodigo, 7, 0);
$this->codigoBarras .= $this->geraNossoNumero();
$this->codigoBarras .= Util::dataJuliano($this->getDataVencimento());
$this->codigoBarras .= 2;
}
if ($this->carteira == 'csb') {
$this->agenciaConta = sprintf('%s-%s', $this->getAgencia(), $this->getAgencia() . $this->getConta());
$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->geraNossoNumero();
$this->codigoBarras .= Util::numberFormatGeral($this->getAgencia(), 4, 0) . Util::numberFormatGeral($this->getConta(), 7, 0);
$this->codigoBarras .= '00';
$this->codigoBarras .= '1';
}
$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);
return $this->codigoBarras;
}