protected function getCampoLivre()
{
if ($this->campoLivre) {
return $this->campoLivre;
}
$length = strlen($this->getConvenio());
$nossoNumero = $this->gerarNossoNumero();
if (strlen($this->getNumero()) > 10) {
if ($length == 6 && in_array($this->getCarteira(), ['16', '18']) && Util::numberFormatGeral($this->getVariacaoCarteira(), 3) == '017') {
return $this->campoLivre = Util::numberFormatGeral($this->getConvenio(), 6) . $nossoNumero . '21';
} else {
throw new \Exception('Só é possível criar um boleto com mais de 10 dígitos no nosso número quando a carteira é 21 e o convênio possuir 6 dígitos.');
}
}
switch ($length) {
case 4:
case 6:
return $this->campoLivre = $nossoNumero . Util::numberFormatGeral($this->getAgencia(), 4) . Util::numberFormatGeral($this->getConta(), 8) . Util::numberFormatGeral($this->getCarteira(), 2);
case 7:
return $this->campoLivre = '000000' . $nossoNumero . Util::numberFormatGeral($this->getCarteira(), 2);
}
throw new \Exception('O código do convênio precisa ter 4, 6 ou 7 dígitos!');
}