modulo11() 공개 정적인 메소드

public static modulo11 ( $n, integer $factor = 2, integer $base = 9, integer $rest, integer $whenTen ) : integer
$n
$factor integer
$base integer
$rest integer
$whenTen integer
리턴 integer
예제 #1
0
 private function geraNossoNumero()
 {
     $nossonumero = Util::numberFormatGeral($this->getNumero(), 7, 0) . Util::modulo11($this->getNumero());
     $this->nossoNumero = Util::numberFormatGeral($this->getNumero(), 7, 0) . '-' . Util::modulo11($this->getNumero());
     return str_pad($nossonumero, 13, "0", STR_PAD_LEFT);
     #completo com zeros na esquerda até atingir 13 caracteres
 }
예제 #2
0
 private function gerarNossoNumero()
 {
     $nossoNumero = Util::numberFormatGeral($this->getNumero(), 11, 0);
     $dv = Util::modulo11($nossoNumero, 7, 0, 'P');
     $this->nossoNumero = $this->getCarteira() . '/' . $nossoNumero . '-' . $dv;
     return $nossoNumero;
 }
예제 #3
0
 /**
  * Método para gerar o código da posição de 20 a 44
  *
  * @return string
  * @throws \Exception
  */
 protected function getCampoLivre()
 {
     if ($this->campoLivre) {
         return $this->campoLivre;
     }
     $nossoNumero = Util::numberFormatGeral($this->gerarNossoNumero(), 17);
     $beneficiario = Util::numberFormatGeral($this->getConta(), 6);
     // Código do beneficiário + DV]
     $campoLivre = $beneficiario . Util::modulo11($beneficiario);
     // Sequencia 1 (posições 3-5 NN) + Constante 1 (1 => registrada, 2 => sem registro)
     $carteira = $this->getCarteira();
     if ($carteira == 'SR') {
         $constante = '2';
     } else {
         $constante = '1';
     }
     $campoLivre .= substr($nossoNumero, 2, 3) . $constante;
     // Sequencia 2 (posições 6-8 NN) + Constante 2 (4-Beneficiário)
     $campoLivre .= substr($nossoNumero, 5, 3) . '4';
     // Sequencia 3 (posições 9-17 NN)
     $campoLivre .= substr($nossoNumero, 8, 9);
     // DV do Campo Livre
     $campoLivre .= Util::modulo11($campoLivre);
     return $this->campoLivre = $campoLivre;
 }
 public function getBanco($verificacao = false)
 {
     if ($verificacao) {
         return sprintf('%s-%s', $this->banco, Util::modulo11($this->banco));
     }
     return $this->banco;
 }
예제 #5
0
 public function addDetalhe(Detalhe $detalhe)
 {
     $this->iniciaDetalhe();
     $this->total += $detalhe->getValor();
     if (in_array('06', $detalhe->getInstrucoes())) {
         $detalhe->diasProtesto = '00';
     }
     $this->add(1, 1, '1');
     $this->add(2, 3, '02');
     $this->add(4, 17, Util::formatCnab('9L', $this->getCedenteDocumento(), 14));
     $this->add(18, 37, Util::formatCnab('9', $this->getCodigoTransmissao(), 20));
     $this->add(38, 62, Util::formatCnab('X', $detalhe->getNumeroControleString(), 25));
     $this->add(63, 69, Util::formatCnab('9', $detalhe->getNumero(), 7));
     $this->add(70, 70, Util::modulo11($detalhe->getNumero()));
     $this->add(71, 76, Util::formatCnab('D', $detalhe->getDataLimiteDesconto(), 6));
     $this->add(77, 77, '');
     $this->add(78, 78, $detalhe->getTaxaMulta() ? '4' : '0');
     $this->add(79, 82, Util::formatCnab('9', $detalhe->getTaxaMulta(), 4, 2));
     $this->add(83, 84, '00');
     $this->add(85, 97, Util::formatCnab('9', 0, 13, 2));
     $this->add(98, 101, '');
     $this->add(102, 107, Util::formatCnab('9', $detalhe->getDataMulta(), 6));
     $this->add(108, 108, $this->getCarteira('1'));
     $this->add(109, 110, '01');
     $this->add(111, 120, Util::formatCnab('X', $detalhe->getNumeroDocumento(), 10));
     $this->add(121, 126, Util::formatCnab('D', $detalhe->getDataVencimento(), 6));
     $this->add(127, 139, Util::formatCnab('9', $detalhe->getValor(), 13, 2));
     $this->add(140, 142, self::COD_BANCO_SANTANDER);
     $this->add(143, 147, '00000');
     $this->add(148, 149, $detalhe->getEspecie('01'));
     $this->add(150, 150, $detalhe->getAceite('N'));
     $this->add(151, 156, Util::formatCnab('D', $detalhe->getDataDocumento(), 6));
     $this->add(157, 158, $detalhe->getInstrucao1('00'));
     $this->add(159, 160, $detalhe->getInstrucao2('00'));
     $this->add(161, 173, Util::formatCnab('9', $detalhe->getValorMora(), 13, 2));
     $this->add(174, 179, Util::formatCnab('D', $detalhe->getDataLimiteDesconto(), 6));
     $this->add(180, 192, Util::formatCnab('9', $detalhe->getValorDesconto(), 13, 2));
     $this->add(193, 205, Util::formatCnab('9', $detalhe->getvalorIOF(), 13, 2));
     $this->add(206, 218, Util::formatCnab('9', $detalhe->getValorAbatimento(), 13, 2));
     $this->add(219, 220, Util::formatCnab('9L', $detalhe->getSacadoTipoDocumento(), 2));
     $this->add(221, 234, Util::formatCnab('9L', $detalhe->getSacadoDocumento(), 14));
     $this->add(235, 274, Util::formatCnab('X', $detalhe->getSacadoNome(), 40));
     $this->add(275, 314, Util::formatCnab('X', $detalhe->getSacadoEndereco(), 40));
     $this->add(315, 326, Util::formatCnab('X', $detalhe->getSacadoBairro(), 12));
     $this->add(327, 334, Util::formatCnab('9L', $detalhe->getSacadoCEP(), 8));
     $this->add(335, 349, Util::formatCnab('X', $detalhe->getSacadoCidade(), 15));
     $this->add(350, 351, Util::formatCnab('X', $detalhe->getSacadoEstado(), 2));
     $this->add(352, 381, Util::formatCnab('X', $detalhe->getSacadorAvalista(), 30));
     $this->add(382, 382, '');
     $this->add(383, 383, 'I');
     $this->add(384, 385, substr($this->getConta(), -2));
     $this->add(386, 391, '');
     $this->add(392, 393, Util::formatCnab('9', $detalhe->getDiasProtesto(), 2));
     $this->add(394, 394, '');
     $this->add(395, 400, Util::formatCnab('N', $this->iRegistros + 1, 6));
     return $this;
 }
예제 #6
0
 /**
  * Gera o Duplo digito do nosso npumero
  * @param $nossoNumero
  * @return int
  */
 private function duploDigitoBanrisul($nossoNumero)
 {
     $dv1 = Util::modulo10($nossoNumero);
     $dv2 = Util::modulo11($nossoNumero . $dv1, 2, 7, 0, 10);
     if ($dv2 == 10) {
         $dv1++;
         $dv2 = Util::modulo11($nossoNumero . $dv1, 2, 7, 0, 10);
         if ($dv1 > 9) {
             $dv1 = 0;
         }
     }
     return $dv1 . $dv2;
 }
예제 #7
0
 protected function gerarCodigoBarras()
 {
     $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->getCarteira(), 3, 0);
     $this->codigoBarras .= $this->geraNossoNumero();
     $this->codigoBarras .= Util::numberFormatGeral($this->getAgencia(), 4, 0);
     $this->codigoBarras .= Util::numberFormatGeral($this->getConta(), 5, 0);
     $this->codigoBarras .= Util::modulo10($this->getAgencia() . $this->getConta());
     $this->codigoBarras .= '000';
     $d = 11 - Util::modulo11($this->codigoBarras, 9, 1);
     $dv = $d == 0 || $d == 1 || $d == 10 || $d == 11 ? 1 : $d;
     $this->codigoBarras = substr($this->codigoBarras, 0, 4) . $dv . substr($this->codigoBarras, 4);
     return $this->codigoBarras;
 }
예제 #8
0
 /**
  * Método para gerar o código da posição de 20 a 44
  *
  * @return string
  */
 protected function getCampoLivre()
 {
     if ($this->campoLivre) {
         return $this->campoLivre;
     }
     $ag = Util::numberFormatGeral($this->getAgencia(), 4);
     $cc = Util::numberFormatGeral($this->getConta(), 6);
     $agCc = $ag . $cc . ($this->getContaDv() ? $this->getContaDv() : Util::modulo11($ag . $cc));
     return $this->campoLivre = $this->getNossoNumero() . $agCc . '00' . '1';
     // Codigo do aplicativo
 }
예제 #9
0
 public function addBoleto(BoletoContract $boleto)
 {
     $this->iniciaDetalhe();
     $this->total += $boleto->getValor();
     $this->add(1, 1, '1');
     $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, 37, Util::formatCnab('9', $this->getCodigoTransmissao(), 20));
     $this->add(38, 62, Util::formatCnab('X', $boleto->getNumero(), 25));
     // numero de controle
     $this->add(63, 70, Util::numberFormatGeral($boleto->getNumeroDocumento(), 7) . Util::modulo11($boleto->getNumeroDocumento()));
     $this->add(71, 76, '000000');
     $this->add(77, 77, '');
     $this->add(78, 78, $boleto->getMulta() > 0 ? '4' : '0');
     $this->add(79, 82, Util::formatCnab('9', $boleto->getMulta(), 4, 2));
     $this->add(83, 84, '00');
     $this->add(85, 97, Util::formatCnab('9', 0, 13, 2));
     $this->add(98, 101, '');
     $this->add(102, 107, $boleto->getDataVencimento()->copy()->addDays($boleto->getJurosApos())->format('dmy'));
     $this->add(108, 108, $this->getCarteiraNumero() > 200 ? '1' : '5');
     $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, '00000');
     $this->add(148, 149, $boleto->getEspecieDocCodigo());
     $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);
     }
     $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, 349, Util::formatCnab('X', $boleto->getPagador()->getCidade(), 15));
     $this->add(350, 351, Util::formatCnab('X', $boleto->getPagador()->getUf(), 2));
     $this->add(352, 381, Util::formatCnab('X', $boleto->getSacadorAvalista() ? $boleto->getSacadorAvalista()->getNome() : '', 30));
     $this->add(382, 382, '');
     $this->add(383, 383, 'I');
     $this->add(384, 385, substr($this->getConta(), -2));
     $this->add(386, 391, '');
     $this->add(392, 393, Util::formatCnab('9', $boleto->getDiasProtesto('0'), 2));
     $this->add(394, 394, '');
     $this->add(395, 400, Util::formatCnab('9', $this->iRegistros + 1, 6));
     return $this;
 }
예제 #10
0
 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;
 }
예제 #11
0
 /**
  * Gera o Nosso Número.
  *
  * @return string
  */
 protected function gerarNossoNumero()
 {
     $nossoNumero = Util::numberFormatGeral($this->getNumero(), 12);
     $nossoNumero .= Util::modulo11($this->getNumero());
     return $nossoNumero;
 }
예제 #12
0
 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));
     }
 }
예제 #13
0
 public function addDetalhe(Detalhe $detalhe)
 {
     $this->iniciaDetalhe();
     $convenio6 = strlen($this->getConvenio()) < 7 ? true : false;
     if ($convenio6) {
         $prefixoTitulo = 'AI';
         if (in_array($this->getCarteira('17'), ['11', '31', '51'])) {
             $nossoNumero = Util::formatCnab('9', 0, 11);
             if ($this->getCarteira('17') != '11') {
                 $prefixoTitulo = 'SD';
             }
         } else {
             $nossoNumero = Util::formatCnab('9', $this->getConvenio(), 6) . Util::formatCnab('9', $detalhe->getNumero(), 5);
         }
         if ($this->getCarteira('17') == '12') {
             $prefixoTitulo .= 'U';
         }
     } else {
         if (in_array($this->getCarteira('17'), ['11', '31', '51'])) {
             $nossoNumero = Util::formatCnab('9', 0, 17);
         } else {
             $nossoNumero = Util::formatCnab('9', $this->getConvenio(), 7) . Util::formatCnab('9', $detalhe->getNumero(), 10);
         }
     }
     if (!in_array('06', [$detalhe->getInstrucao1(), $detalhe->getInstrucao2()])) {
         $detalhe->diasProtesto = '00';
     }
     $idArquivo = $convenio6 ? 1 : 7;
     $this->add(1, 1, $idArquivo);
     $this->add(2, 3, '02');
     $this->add(4, 17, Util::formatCnab('L', $this->cedenteDocumento, 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()));
     if ($convenio6) {
         $this->add(32, 37, Util::formatCnab('9', $this->getConvenio(), 6));
         $this->add(38, 62, Util::formatCnab('X', $detalhe->getNumeroControleString(), 25));
         $this->add(63, 73, $nossoNumero);
         $this->add(64, 74, Util::modulo11($nossoNumero));
         $this->add(75, 76, '00');
         $this->add(77, 78, '00');
         $this->add(79, 81, '');
         $this->add(82, 82, $detalhe->getSacadorAvalista() ? 'A' : '');
         $this->add(83, 85, Util::formatCnab('X', $prefixoTitulo, 3));
         $this->add(86, 88, Util::formatCnab('9', $this->carteiraVariacao, 3));
         $this->add(89, 89, '0');
         $this->add(90, 94, '00000');
         $this->add(95, 95, '0');
     } else {
         $this->add(32, 38, Util::formatCnab('9', $this->getConvenio(), 7));
         $this->add(39, 63, Util::formatCnab('X', $detalhe->getNumeroControleString(), 25));
         $this->add(64, 80, $nossoNumero);
         $this->add(81, 82, '00');
         $this->add(83, 84, '00');
         $this->add(85, 87, '');
         $this->add(88, 88, $detalhe->getSacadorAvalista() ? 'A' : '');
         $this->add(89, 91, '');
         $this->add(92, 94, Util::formatCnab('9', $this->carteiraVariacao, 3));
         $this->add(95, 95, '0');
     }
     $this->add(96, 101, '000000');
     $this->add(102, 106, Util::formatCnab('X', $detalhe->getTipoCobrancaBB(), 5));
     $this->add(107, 108, $this->getCarteira('17'));
     $this->add(109, 110, Util::formatCnab('N', $detalhe->getOcorrencia(), 2));
     $this->add(111, 120, Util::formatCnab('X', $detalhe->getNumeroDocumento(), 10));
     $this->add(121, 126, Util::formatCnab('D', $detalhe->getDataVencimento(), 6));
     $this->add(127, 139, Util::formatCnab('9', $detalhe->getValor(), 13, 2));
     $this->add(140, 142, self::COD_BANCO_BB);
     $this->add(143, 146, '0000');
     $this->add(147, 147, '');
     $this->add(148, 149, $detalhe->getEspecie('01'));
     $this->add(150, 150, $detalhe->getAceite('N'));
     $this->add(151, 156, Util::formatCnab('D', $detalhe->getDataDocumento(), 6));
     $this->add(157, 158, Util::formatCnab('9', $detalhe->getInstrucao1('00'), 2));
     $this->add(159, 160, Util::formatCnab('9', $detalhe->getInstrucao2('00'), 2));
     $this->add(161, 173, Util::formatCnab('9', $detalhe->getValorMora(), 13, 2));
     $this->add(174, 179, Util::formatCnab('9', $detalhe->getDataLimiteDesconto('0'), 6));
     $this->add(180, 192, Util::formatCnab('9', $detalhe->getValorDesconto(), 13, 2));
     $this->add(193, 205, Util::formatCnab('9', $detalhe->getvalorIOF(), 13, 2));
     $this->add(206, 218, Util::formatCnab('9', $detalhe->getValorAbatimento(), 13, 2));
     $this->add(219, 220, Util::formatCnab('9', $detalhe->getSacadoTipoDocumento(), 2));
     $this->add(221, 234, Util::formatCnab('9', $detalhe->getSacadoDocumento(), 14));
     $this->add(235, 271, Util::formatCnab('X', $detalhe->getSacadoNome(), 37));
     $this->add(272, 274, '');
     if ($convenio6) {
         $this->add(275, 326, Util::formatCnab('X', $detalhe->getSacadoEndereco(), 52));
     } else {
         $this->add(275, 311, Util::formatCnab('X', $detalhe->getSacadoEndereco(), 37));
         $this->add(312, 326, '');
     }
     $this->add(327, 334, Util::formatCnab('9', $detalhe->getSacadoCEP(), 8));
     $this->add(335, 349, Util::formatCnab('X', $detalhe->getSacadoCidade(), 15));
     $this->add(350, 351, Util::formatCnab('X', $detalhe->getSacadoEstado(), 2));
     $this->add(352, 391, Util::formatCnab('X', $detalhe->getSacadorAvalista(), 40));
     $this->add(392, 393, Util::formatCnab('9', $detalhe->getDiasProtesto(), 2));
     $this->add(394, 394, '');
     $this->add(395, 400, Util::formatCnab('N', $this->iRegistros + 1, 6));
 }
예제 #14
0
 private function geraNossoNumero()
 {
     if ($this->carteira == 'cnr') {
         if ($this->getNumero() && $this->cedenteCodigo && $this->getDataVencimento()) {
             $nossonumero = Util::numberFormatGeral($this->getNumero(), 13, 0);
             $nossonumero .= Util::modulo11Reverso($nossonumero) . '4';
             $nossonumero .= Util::modulo11Reverso($nossonumero + $this->cedenteCodigo + $this->getDataVencimento()->format('dmy'));
             $this->nossoNumero = $nossonumero;
             return Util::numberFormatGeral($this->numero, 13, 0);
         } else {
             throw new Exception('Todos os parâmetros devem ser informados {numero,contaCorrente,vencimento}');
         }
     }
     if ($this->carteira == 'csb') {
         if ($this->range && $this->getNumero()) {
             $nossonumero = Util::numberFormatGeral($this->range, 5, 0) . Util::numberFormatGeral($this->numero, 5, 0);
             $nossonumero .= Util::modulo11($nossonumero, 7);
             $this->nossoNumero = $nossonumero;
             return $nossonumero;
         } else {
             throw new Exception('Todos os parâmetros devem ser informados {numero,range}');
         }
     }
 }
예제 #15
0
 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', $boleto->getNumero(), 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, '');
     $this->add(107, 108, $this->getCarteiraNumero());
     $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, 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, self::INSTRUCAO_SEM);
     $this->add(159, 160, self::INSTRUCAO_SEM);
     $diasProtesto = '00';
     $const = sprintf('self::INSTRUCAO_PROTESTAR_VENC_%02s', $boleto->getDiasProtesto());
     if (defined($const)) {
         $this->add(157, 158, constant($const));
     } else {
         $this->add(157, 158, self::INSTRUCAO_PROTESTAR_VENC_XX);
         $diasProtesto = Util::formatCnab('9', $boleto->getDiasProtesto(), 2, 0);
     }
     $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, 271, Util::formatCnab('X', $boleto->getPagador()->getNome(), 37));
     $this->add(272, 274, '');
     $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, $diasProtesto);
     $this->add(394, 394, '');
     $this->add(395, 400, Util::formatCnab('9', $this->iRegistros + 1, 6));
     if ($boleto->getMulta() > 0) {
         $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())->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('9', $this->iRegistros + 1, 6));
     }
 }
예제 #16
0
 private function arrumaCodCedente()
 {
     $_4first = substr($this->getCedenteCodigo(), 0, 4);
     $agencia = Util::formatCnab('9', $this->getAgencia(), 4);
     if ($_4first != $agencia) {
         if (strlen($this->getCedenteCodigo()) == 12) {
             $this->cedenteCodigo = $agencia . $this->getCedenteCodigo();
         } else {
             if (strlen($this->getCedenteCodigo()) == 11) {
                 $this->cedenteCodigo = $agencia . $this->getCedenteCodigo();
                 $this->cedenteCodigo .= Util::modulo11($this->getCedenteCodigo());
             } else {
                 throw new \Exception('Codigo de cedente inválido, formato: PPPXXXXXXXXD');
             }
         }
     }
 }
예제 #17
0
 /**
  * Método para gerar o código da posição de 20 a 44
  *
  * @return string
  * @throws \Exception
  */
 protected function getCampoLivre()
 {
     if ($this->campoLivre) {
         return $this->campoLivre;
     }
     $tipo_cobranca = $this->isComRegistro() ? '1' : '3';
     $carteira = Util::numberFormatGeral($this->getCarteira(), 1);
     $nosso_numero = $this->getNossoNumero();
     $agencia = Util::numberFormatGeral($this->getAgencia(), 4);
     $posto = Util::numberFormatGeral($this->getPosto(), 2);
     $conta = Util::numberFormatGeral($this->getConta(), 5);
     $possui_valor = $this->getValor() > 0 ? '1' : '0';
     $campo_livre = $tipo_cobranca . $carteira . $nosso_numero . $agencia . $posto . $conta . $possui_valor . '0';
     return $this->campoLivre = $campo_livre . Util::modulo11($campo_livre);
 }
예제 #18
0
 /**
  * Método que retorna o nosso numero usado no boleto. alguns bancos possuem algumas diferenças.
  *
  * @return string
  */
 public function getNossoNumeroBoleto()
 {
     $nn = $this->getNossoNumero();
     return strlen($nn) < 17 ? $nn . '-' . Util::modulo11($nn) : $nn;
 }
예제 #19
0
 protected function gerarNossoNumero()
 {
     if ($this->convenioFormato == '8') {
         $nossoNumero = Util::numberFormatGeral($this->getNumero(), 9, 0);
         $this->nossoNumero = $this->convenio . $nossoNumero . "-" . Util::modulo11($this - $this->convenio . $nossoNumero);
     } else {
         if ($this->convenioFormato == "7") {
             $nossoNumero = Util::numberFormatGeral($this->getNumero(), 10, 0);
             $this->nossoNumero = $this->convenio . $nossoNumero . "-" . Util::modulo11($this->convenio . $nossoNumero);
             $this->nossoNumero = $this->convenio . $nossoNumero;
         } else {
             if ($this->convenioFormato == "6") {
                 if ($this->nossoNumeroFormato == 1) {
                     $nossoNumero = Util::numberFormatGeral($this->getNumero(), 5, 0);
                     $this->nossoNumero = $this->convenio . $nossoNumero . "-" . Util::modulo11($this->convenio . $nossoNumero);
                 } else {
                     if ($this->nossoNumeroFormato == 2) {
                         $nossoNumero = Util::numberFormatGeral($this->getNumero(), 17, 0);
                         $this->nossoNumero = $nossoNumero;
                     } else {
                         throw new \Exception('Campo formatacaoNN inválido, deve possuir {1|2}');
                     }
                 }
             } else {
                 throw new \Exception('Formato de convenio inválido, deve possuir {6|7|8} digitos');
             }
         }
     }
     return $nossoNumero;
 }
예제 #20
0
 private function geraNossoNumero()
 {
     $nossonumero = Util::numberFormatGeral($this->getNumero(), 7, 0) . Util::modulo11($this->getNumero());
     $this->nossoNumero = Util::numberFormatGeral($this->getNumero(), 7, 0) . '-' . Util::modulo11($this->getNumero());
     return sprintf('%013s', $nossonumero);
 }
예제 #21
0
 public function addDetalhe(Detalhe $detalhe)
 {
     $this->iniciaDetalhe();
     $idempresa = '0';
     $idempresa .= Util::formatCnab('N', $this->getCarteira('21'), 3);
     $idempresa .= Util::formatCnab('N', $this->getAcencia(), 5);
     $idempresa .= Util::formatCnab('N', $this->getConta(), 7);
     $idempresa .= Util::modulo11($this->getConta());
     $dvNossoNumero = Util::modulo11(Util::formatCnab('N', $this->getCarteira('21'), 2) . Util::formatCnab('N', $detalhe->getNumero(), 11), 7, 0, 'P');
     $dvNossoNumero = $detalhe->getNumero() > 0 ? $dvNossoNumero : 0;
     $this->add(1, 1, '1');
     if ($this->debitoAutomatico) {
         /**
          *
          * 002 a 020 - Identificação do Débito Automático em C/C
          * Somente deverão ser preenchidos, caso o cliente Cedente esteja previamente cadastrado
          * para operar com a modalidade de débito automático em Conta do cliente pagador (Sacado),
          * cujos campos correspondentes a essas posições são:
          * - posição 002 a 006 = no da Agência a ser debitada, ou seja, do Sacado
          * - posição 007 a 007 = dígito da Agência a ser debitada
          * - posição 008 a 012 = razão da Conta  - Ex. 07050
          * - posição 013 a 019 = no da Conta Corrente do Sacado
          * - posição 020 a 020 = dígito da Conta Corrente do Sacado
          *
          */
         $this->add(2, 6, Util::formatCnab('N', $this->getAgencia(), 5));
         $this->add(7, 7, Util::modulo11($this->getAgencia()));
         $this->add(8, 12, Util::formatCnab('N', $this->getContaRazao(), 5));
         $this->add(13, 19, Util::formatCnab('N', $this->getConta(), 7));
         $this->add(20, 20, Util::modulo11($this->getConta()));
     } else {
         $this->add(2, 6, Util::formatCnab('A', '', 5));
         $this->add(7, 7, '');
         $this->add(8, 12, Util::formatCnab('A', '', 5));
         $this->add(13, 19, Util::formatCnab('A', '', 7));
         $this->add(20, 20, '');
     }
     if ($detalhe->getTaxaMulta()) {
         $tipoMulta = 2;
         $multa = $detalhe->getTaxaMulta();
     } elseif ($detalhe->getValorMulta()) {
         $tipoMulta = 0;
         $multa = $detalhe->getValorMulta();
     } else {
         $tipoMulta = ' ';
         $multa = 0;
     }
     $this->add(21, 37, Util::formatCnab('A', $idempresa, 17));
     $this->add(38, 62, Util::formatCnab('A', $detalhe->getNumeroControleString(), 25));
     $this->add(63, 65, self::COD_BANCO_BRADESCO);
     $this->add(66, 66, $tipoMulta);
     $this->add(67, 70, Util::formatCnab('N', $multa, 4, 2));
     $this->add(71, 81, Util::formatCnab('N', $detalhe->getNumero(), 11));
     $this->add(82, 82, $dvNossoNumero);
     $this->add(83, 92, Util::formatCnab('N', $detalhe->getValorDesconto(), 10, 2));
     $this->add(93, 93, $detalhe->getNumero() > 0 ? '2' : '1');
     $this->add(94, 94, $detalhe->getNumero() > 0 ? 'N' : ' ');
     $this->add(95, 104, '');
     $this->add(105, 105, 'R');
     $this->add(106, 106, '2');
     $this->add(107, 108, '');
     $this->add(109, 110, Util::formatCnab('N', $detalhe->getOcorrencia(), 2));
     $this->add(111, 120, Util::formatCnab('A', $detalhe->getNumeroDocumento(), 10));
     $this->add(121, 126, Util::formatCnab('D', $detalhe->getDataVencimento(), 6));
     $this->add(127, 139, Util::formatCnab('N', $detalhe->getValor(), 13, 2));
     $this->add(140, 142, Util::formatCnab('A', '', 3));
     $this->add(143, 147, Util::formatCnab('A', '', 5));
     $this->add(148, 149, $detalhe->getEspecie('01'));
     $this->add(150, 150, $detalhe->getAceite('N'));
     $this->add(151, 156, Util::formatCnab('D', $detalhe->getDataDocumento(), 6));
     $this->add(157, 158, $detalhe->getInstrucao1('00'));
     $this->add(159, 160, $detalhe->getInstrucao2('00'));
     $this->add(161, 173, Util::formatCnab('N', $detalhe->getValorMora(), 13, 2));
     $this->add(174, 179, Util::formatCnab('D', $detalhe->getDataLimiteDesconto(), 6));
     $this->add(180, 192, Util::formatCnab('N', $detalhe->getValorDesconto(), 13, 2));
     $this->add(193, 205, Util::formatCnab('N', $detalhe->getvalorIOF(), 13, 2));
     $this->add(206, 218, Util::formatCnab('N', $detalhe->getValorAbatimento(), 13, 2));
     $this->add(219, 220, Util::formatCnab('NL', $detalhe->getSacadoTipoDocumento(), 2));
     $this->add(221, 234, Util::formatCnab('L', $detalhe->getSacadoDocumento(), 14));
     $this->add(235, 274, Util::formatCnab('A', $detalhe->getSacadoNome(), 40));
     $this->add(275, 314, Util::formatCnab('A', $detalhe->getSacadoEndereco(), 40));
     $this->add(315, 326, '');
     $this->add(327, 331, substr($detalhe->getSacadoCEP(), 0, 5));
     $this->add(332, 334, substr($detalhe->getSacadoCEP(), -3));
     $this->add(335, 394, Util::formatCnab('A', $detalhe->getSacadorAvalista(), 60));
     $this->add(395, 400, Util::formatCnab('N', $this->iRegistros + 1, 6));
     return $this;
 }
예제 #22
0
 /**
  * Método que retorna o nosso numero usado no boleto. alguns bancos possuem algumas diferenças.
  *
  * @return string
  */
 public function getNossoNumeroBoleto()
 {
     return Util::numberFormatGeral($this->getCarteira(), 2) . ' / ' . $this->getNossoNumero() . '-' . Util::modulo11($this->getCarteira() . $this->getNossoNumero(), 2, 7, 0, 'P');
 }
예제 #23
0
 private function gerarNossoNumero()
 {
     if ($this->tipo == self::CEF_TIPO_POS11) {
         $tNN = 10 - strlen($this->getCarteira());
         $nossoNumero = substr($this->getNumero(), $tNN * -1);
         $nossoNumero = $this->getCarteira() . Util::numberFormatGeral($nossoNumero, $tNN, '0');
         $d = 11 - Util::modulo11($nossoNumero, 9, 1);
         $dv = $d == 10 || $d == 11 ? '0' : $d;
         $nossoNumero = $nossoNumero;
         $this->nossoNumero = $nossoNumero . '-' . $dv;
         return $nossoNumero;
     } else {
         if ($this->tipo == self::CEF_TIPO_POS16) {
             $nossoNumero = "8" . Util::numberFormatGeral(substr($this->numero, -14), 14, 0);
             $d = 11 - Util::modulo11($nossoNumero, 9, 1);
             $dv = $d > 9 ? '0' : $d;
             $nossoNumero = $nossoNumero;
             $this->nossoNumero = $nossoNumero . '-' . $dv;
             return $nossoNumero;
         }
     }
 }
예제 #24
0
 /**
  * Retorna o código do banco com o dígito verificador
  *
  * @return string
  */
 public function getCodigoBancoComDv()
 {
     $codigoBanco = $this->getCodigoBanco();
     return $codigoBanco . '-' . Util::modulo11($codigoBanco);
 }
예제 #25
0
 public function addDetalhe(Detalhe $detalhe)
 {
     $this->iniciaDetalhe();
     $nossoNumero = Util::formatCnab('N', $this->getRange(), 5) . Util::formatCnab('N', $detalhe->getNumero(), 5);
     $nossoNumero = $nossoNumero . Util::modulo11($nossoNumero, 7);
     if ($detalhe->getEspecie('01') == '09') {
         $nossoNumero = 0;
     }
     $this->add(1, 1, '1');
     $this->add(2, 3, '02');
     $this->add(4, 17, Util::formatCnab('NL', $this->getCedenteDocumento(), 14));
     $this->add(18, 18, 0);
     $this->add(19, 22, Util::formatCnab('N', $this->getAgencia(), 4));
     $this->add(23, 24, '55');
     $this->add(25, 28, Util::formatCnab('NL', $this->getAgencia(), 4));
     $this->add(29, 35, Util::formatCnab('NL', $this->getConta(), 7));
     $this->add(36, 37, '');
     $this->add(38, 62, Util::formatCnab('X', $detalhe->getNumeroControleString(), 25));
     $this->add(63, 73, Util::formatCnab('N', $nossoNumero, 11));
     $this->add(74, 79, '000000');
     $this->add(80, 90, Util::formatCnab('N', 0, 11, 2));
     $this->add(91, 96, '000000');
     $this->add(97, 107, Util::formatCnab('N', 0, 11, 2));
     $this->add(108, 108, $this->getCarteira('1'));
     $this->add(109, 110, '01');
     $this->add(111, 120, Util::formatCnab('X', $detalhe->getNumeroDocumento(), 10));
     $this->add(121, 126, Util::formatCnab('D', $detalhe->getDataVencimento(), 6));
     $this->add(127, 139, Util::formatCnab('N', $detalhe->getValor(), 13, 2));
     $this->add(140, 142, self::COD_BANCO_HSBC);
     $this->add(143, 147, Util::formatCnab('N', "0", 5));
     $this->add(148, 149, $detalhe->getEspecie('01'));
     $this->add(150, 150, $detalhe->getAceite('N'));
     $this->add(151, 156, Util::formatCnab('D', $detalhe->getDataDocumento(), 6));
     $this->add(157, 158, $detalhe->getInstrucao1('00'));
     $this->add(159, 160, $detalhe->getInstrucao2('00'));
     $this->add(161, 173, Util::formatCnab('N', $detalhe->getValorMora(), 13, 2));
     $this->add(174, 179, Util::formatCnab('D', $detalhe->getDataLimiteDesconto(), 6));
     $this->add(180, 192, Util::formatCnab('N', $detalhe->getValorDesconto(), 13, 2));
     $this->add(193, 205, Util::formatCnab('N', $detalhe->getvalorIOF(), 13, 2));
     $this->add(206, 218, Util::formatCnab('N', $detalhe->getValorAbatimento(), 13, 2));
     $this->add(219, 220, Util::formatCnab('NL', $detalhe->getSacadoTipoDocumento(), 2));
     $this->add(221, 234, Util::formatCnab('L', $detalhe->getSacadoDocumento(), 14));
     $this->add(235, 274, Util::formatCnab('A', $detalhe->getSacadoNome(), 40));
     $this->add(275, 312, Util::formatCnab('A', $detalhe->getSacadoEndereco(), 38));
     $this->add(313, 314, Util::formatCnab('N', $detalhe->getNaoReceberDias(), 2));
     $this->add(315, 326, Util::formatCnab('A', $detalhe->getSacadoBairro(), 12));
     $this->add(327, 331, substr($detalhe->getSacadoCEP(), 0, 5));
     $this->add(332, 334, substr($detalhe->getSacadoCEP(), -3));
     $this->add(335, 349, Util::formatCnab('A', $detalhe->getSacadoCidade(), 15));
     $this->add(350, 351, Util::formatCnab('A', $detalhe->getSacadoEstado(), 2));
     $this->add(352, 390, Util::formatCnab('A', $detalhe->getSacadorAvalista(), 39));
     $this->add(391, 391, '');
     $this->add(392, 393, Util::formatCnab('N', $detalhe->getDiasProtesto(), 2));
     $this->add(394, 394, $detalhe->getTipoMoeda('9'));
     $this->add(395, 400, Util::formatCnab('N', $this->iRegistros + 1, 6));
     if (in_array('15', $detalhe->getInstrucoes()) || in_array('16', $detalhe->getInstrucoes()) || in_array('29', $detalhe->getInstrucoes())) {
         if (in_array('29', $detalhe->getInstrucoes())) {
             $detalhe->taxaMulta = 0;
         }
         if (empty($detalhe->getDataMulta()) || empty($detalhe->getTaxaMulta())) {
             throw new \Exception('Campos ausentes {dataMulta|taxaMulta}');
         }
         $string = Util::formatCnab('D', $detalhe->getDataMulta(), 6) . Util::formatCnab('N', $detalhe->getTaxaMulta(), 4, 2) . '000';
         $this->add(206, 218, Util::formatCnab('A', $string, 13, 0, 0));
     }
     if (in_array('19', $detalhe->getInstrucoes()) || in_array('22', $detalhe->getInstrucoes()) || in_array('24', $detalhe->getInstrucoes())) {
         if (in_array('24', $detalhe->getInstrucoes())) {
             $detalhe->xDiasMulta = 0;
         }
         if (empty($detalhe->getXDiasMulta()) || empty($detalhe->getValorMulta())) {
             throw new \Exception('Campos ausentes {xDiasMulta|valorMulta}');
         }
         $string = Util::formatCnab('N', $detalhe->getValorMulta(), 10, 2) . Util::formatCnab('N', $detalhe->getXDiasMulta(), 3);
         $this->add(206, 218, Util::formatCnab('A', $string, 13, 0, 0));
     }
     if (in_array('73', $detalhe->getInstrucoes()) || in_array('74', $detalhe->getInstrucoes())) {
         if (empty($detalhe->getTaxaMulta()) || empty($detalhe->getXDiasMulta())) {
             throw new \Exception('Campos ausentes {taxaMulta|xDiasMulta}');
         }
         $string = Util::formatCnab('A', '', 6) . Util::formatCnab('N', $detalhe->getTaxaMulta(), 4, 2) . Util::formatCnab('N', $detalhe->getXDiasMulta(), 3);
         $this->add(206, 218, Util::formatCnab('A', $string, 13, 0, 0));
     }
 }