public function addBoleto(BoletoContract $boleto)
{
$this->iniciaDetalhe();
$this->add(1, 1, 7);
$this->add(2, 3, strlen(Util::onlyNumbers($this->getBeneficiario()->getDocumento())) == 14 ? '02' : '01');
$this->add(4, 17, Util::formatCnab('9L', $this->getBeneficiario()->getDocumento(), 14));
$this->add(18, 21, Util::formatCnab('9', $this->getAgencia(), 4));
$this->add(22, 22, Util::modulo11($this->getAgencia()));
$this->add(23, 30, Util::formatCnab('9', $this->getConta(), 8));
$this->add(31, 31, Util::modulo11($this->getConta()));
$this->add(32, 38, Util::formatCnab('9', $this->getConvenio(), 7));
$this->add(39, 63, Util::formatCnab('X', '', 25));
// numero de controle
$this->add(64, 80, $boleto->getNossoNumero());
$this->add(81, 82, '00');
$this->add(83, 84, '00');
$this->add(85, 87, '');
$this->add(88, 88, $boleto->getSacadorAvalista() ? 'A' : '');
$this->add(89, 91, '');
$this->add(92, 94, Util::formatCnab('9', $this->getVariacaoCarteira(), 3));
$this->add(95, 95, '0');
$this->add(96, 101, '000000');
$this->add(102, 106, Util::formatCnab('X', '', 5));
$this->add(107, 108, $this->getCarteiraNumero());
$this->add(109, 110, '01');
// REGISTRO
if ($boleto->getStatus() == $boleto::STATUS_BAIXA) {
$this->add(109, 110, '02');
// BAIXA
}
if ($boleto->getStatus() == $boleto::STATUS_ALTERACAO) {
$this->add(109, 110, '06');
// ALTERAR VENCIMENTO
}
$this->add(111, 120, Util::formatCnab('X', $boleto->getNumeroDocumento(), 10));
$this->add(121, 126, $boleto->getDataVencimento()->format('dmy'));
$this->add(127, 139, Util::formatCnab('9', $boleto->getValor(), 13, 2));
$this->add(140, 142, $this->getCodigoBanco());
$this->add(143, 146, '0000');
$this->add(147, 147, '');
$this->add(148, 149, $boleto->getEspecieDocCodigo());
$this->add(150, 150, $boleto->getAceite());
$this->add(151, 156, $boleto->getDataDocumento()->format('dmy'));
$this->add(157, 158, '00');
$this->add(159, 160, '00');
switch ($boleto->getDiasProtesto()) {
case '03':
//- 03 - Protestar no 3º dia útil após vencido
$this->add(157, 158, '03');
break;
case '04':
//- 04 - Protestar no 4º dia útil após vencido
$this->add(157, 158, '04');
break;
case '05':
//- 05 - Protestar no 5º dia útil após vencido
$this->add(157, 158, '05');
break;
case '10':
//- 10 - Protestar no 10º dia corrido após vencido
$this->add(157, 158, '10');
break;
case '15':
//- 15 - Protestar no 15º dia corrido após vencido
$this->add(157, 158, '15');
break;
case '20':
//- 20 - Protestar no 20º dia corrido após vencido
$this->add(157, 158, '20');
break;
case '25':
//- 25 - Protestar no 25º dia corrido após vencido
$this->add(157, 158, '25');
break;
case '30':
//- 30 - Protestar no 30º dia corrido após vencido
$this->add(157, 158, '30');
break;
case '45':
//- 45 - Protestar no 45º dia corrido após vencido
$this->add(157, 158, '45');
break;
}
$juros = 0;
if ($boleto->getJuros() !== false) {
$juros = Util::percent($boleto->getValor(), $boleto->getJuros()) / 30;
}
$this->add(161, 173, Util::formatCnab('9', $juros, 13, 2));
$this->add(174, 179, '000000');
$this->add(180, 192, Util::formatCnab('9', 0, 13, 2));
$this->add(193, 205, Util::formatCnab('9', 0, 13, 2));
$this->add(206, 218, Util::formatCnab('9', $boleto->getDescontosAbatimentos(), 13, 2));
$this->add(219, 220, strlen(Util::onlyNumbers($boleto->getPagador()->getDocumento())) == 14 ? '02' : '01');
$this->add(221, 234, Util::formatCnab('9L', $boleto->getPagador()->getDocumento(), 14));
$this->add(235, 271, Util::formatCnab('X', $boleto->getPagador()->getNome(), 37));
$this->add(272, 274, Util::formatCnab('N', '', 3));
$this->add(275, 314, Util::formatCnab('X', $boleto->getPagador()->getEndereco(), 40));
$this->add(315, 326, Util::formatCnab('X', $boleto->getPagador()->getBairro(), 12));
$this->add(327, 334, Util::formatCnab('9L', $boleto->getPagador()->getCep(), 8));
$this->add(335, 349, Util::formatCnab('X', $boleto->getPagador()->getCidade(), 15));
$this->add(350, 351, Util::formatCnab('X', $boleto->getPagador()->getUf(), 2));
$this->add(352, 391, Util::formatCnab('X', $boleto->getSacadorAvalista() ? $boleto->getSacadorAvalista()->getNome() : '', 40));
$this->add(392, 393, '00');
$this->add(394, 394, '');
$this->add(395, 400, Util::formatCnab('N', $this->iRegistros + 1, 6));
if ($boleto->getMulta() !== false) {
$this->iniciaDetalhe();
$this->add(1, 1, 5);
$this->add(2, 3, 99);
$this->add(4, 4, 2);
$this->add(5, 10, $boleto->getDataVencimento()->copy()->addDays($boleto->getJurosApos(0))->format('dmy'));
$this->add(11, 22, Util::formatCnab('9', $boleto->getMulta(), 7, 2));
$this->add(23, 394, '');
$this->add(23, 394, '');
$this->add(395, 400, Util::formatCnab('N', $this->iRegistros + 1, 6));
}
}