Example #1
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;
 }
Example #2
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));
 }