public function addBoleto(BoletoContract $boleto) { $this->iniciaDetalhe(); $beneficiario_id = '0' . Util::formatCnab('9', $this->getCarteiraNumero(), 3) . Util::formatCnab('9', $this->getAgencia(), 5) . Util::formatCnab('9', $this->getConta(), 7) . Util::formatCnab('9', $this->getContaDv(), 1); $this->add(1, 1, '1'); $this->add(2, 6, ''); $this->add(7, 7, ''); $this->add(8, 12, ''); $this->add(13, 19, ''); $this->add(20, 20, ''); $this->add(21, 37, Util::formatCnab('X', $beneficiario_id, 17)); $this->add(38, 62, Util::formatCnab('X', $boleto->getNumero(), 25)); // numero de controle $this->add(63, 65, $this->getCodigoBanco()); $this->add(66, 66, $boleto->getMulta() > 0 ? '2' : '0'); $this->add(67, 70, Util::formatCnab('9', $boleto->getMulta() > 0 ? $boleto->getMulta() : '0', 4, 2)); $this->add(71, 81, Util::formatCnab('9', $boleto->getNossoNumero(), 11)); $this->add(82, 82, Util::modulo11($boleto->getCarteira() . $boleto->getNossoNumero(), 2, 7, 0, 'P')); $this->add(83, 92, Util::formatCnab('9', 0, 10, 2)); $this->add(93, 93, '2'); // 1 = Banco emite e Processa o registro. 2 = Cliente emite e o Banco somente processa o registro $this->add(94, 94, ''); // N= Não registra na cobrança. Diferente de N registra e emite Boleto. $this->add(95, 104, ''); $this->add(105, 105, ''); $this->add(106, 106, '2'); // 1 = emite aviso, e assume o endereço do Pagador constante do Arquivo-Remessa; 2 = não emite aviso; $this->add(107, 108, ''); $this->add(109, 110, self::OCORRENCIA_REMESSA); // REGISTRO if ($boleto->getStatus() == $boleto::STATUS_BAIXA) { $this->add(109, 110, self::OCORRENCIA_PEDIDO_BAIXA); // BAIXA } if ($boleto->getStatus() == $boleto::STATUS_ALTERACAO) { $this->add(109, 110, self::OCORRENCIA_ALT_VENCIMENTO); // 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->add(143, 147, '00000'); $this->add(148, 149, $boleto->getEspecieDocCodigo()); $this->add(150, 150, 'N'); $this->add(151, 156, $boleto->getDataDocumento()->format('dmy')); $this->add(157, 158, self::INSTRUCAO_SEM); $this->add(159, 160, self::INSTRUCAO_SEM); if ($boleto->getDiasProtesto() > 0) { $this->add(157, 158, self::INSTRUCAO_PROTESTAR_XX); $this->add(159, 160, Util::formatCnab('9', $boleto->getDiasProtesto(), 2)); } $juros = 0; if ($boleto->getJuros() > 0) { $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, 274, Util::formatCnab('X', $boleto->getPagador()->getNome(), 40)); $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, 394, Util::formatCnab('X', $boleto->getSacadorAvalista() ? $boleto->getSacadorAvalista()->getNome() : '', 60)); $this->add(395, 400, Util::formatCnab('9', $this->iRegistros + 1, 6)); return $this; }
/** * @param BoletoContract $boleto * @return bool */ public function addBoleto(BoletoContract $boleto) { $this->iniciaDetalhe(); $this->add(1, 1, 1); $this->add(2, 17, ''); $this->add(18, 30, Util::formatCnab('9', $this->getCodigoCliente(), 13, '0')); $this->add(31, 37, ''); $this->add(38, 62, Util::formatCnab('X', $boleto->getNumero(), 25)); $this->add(63, 72, Util::formatCnab('9L', $boleto->getNossoNumero(), 10)); $this->add(73, 104, ''); $this->add(105, 107, ''); $this->add(108, 108, Util::formatCnab('X', $boleto->getCarteira(), 1)); $this->add(109, 110, self::OCORRENCIA_REMESSA); // REGISTRO if ($boleto->getStatus() == $boleto::STATUS_BAIXA) { $this->add(109, 110, self::OCORRENCIA_PEDIDO_BAIXA); // BAIXA } if ($boleto->getStatus() == $boleto::STATUS_ALTERACAO) { $this->add(109, 110, self::OCORRENCIA_ALT_VENCIMENTO); // 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, 147, ''); $this->add(148, 149, $this->isCarteiraRSX() ? '' : self::TIPO_COBRANCA_CREDENCIADA); $this->add(150, 150, $boleto->getAceite()); $this->add(151, 156, $boleto->getDataDocumento()->format('dmy')); $this->add(157, 158, self::INSTRUCAO_SEM); $this->add(159, 160, self::INSTRUCAO_SEM); if ($boleto->getDiasProtesto() > 0) { $this->add(157, 158, self::INSTRUCAO_PROTESTAR_XX); } if ($boleto->getMulta() > 0) { $this->add(159, 160, self::INSTRUCAO_MULTA_XX); } $juros = 0; if ($boleto->getJuros() > 0) { $juros = Util::percent($boleto->getValor(), $boleto->getJuros()) / 30; } $this->add(161, 161, '0'); $this->add(162, 173, Util::formatCnab('9', $juros, 12, 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, 269, Util::formatCnab('X', $boleto->getPagador()->getNome(), 35)); $this->add(270, 274, ''); $this->add(275, 314, Util::formatCnab('X', $boleto->getPagador()->getEndereco(), 40)); $this->add(315, 321, ''); $this->add(322, 324, Util::formatCnab('9', $boleto->getMulta(), 3, 1)); $this->add(325, 326, '00'); $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, 355, Util::formatCnab('9', 0, 3)); $this->add(356, 357, ''); $this->add(358, 369, '00'); $this->add(370, 371, Util::formatCnab('9', $boleto->getDiasProtesto(), 2)); $this->add(372, 394, ''); $this->add(395, 400, Util::formatCnab('9', $this->iRegistros + 1, 6)); $this->valorTotal += $boleto->getValor(); return true; }