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