예제 #1
0
        public override string GerarHeaderLoteRemessa(string numeroConvenio, Cedente cedente, int numeroArquivoRemessa, TipoArquivo tipoArquivo)
        {
            string _headerLote;

            _headerLote = "13600011R01  044 ";
            if (cedente.CPFCNPJ.Length <= 11)
            {
                _headerLote += "1";
            }
            else
            {
                _headerLote += "2";
            }
            _headerLote += Utils.FitStringLength(cedente.CPFCNPJ, 15, 15, '0', 0, true, true, true);
            _headerLote += new string(' ', 20);
            _headerLote += Utils.FitStringLength(cedente.ContaBancaria.Agencia, 5, 5, '0', 0, true, true, true);
            _headerLote += Utils.FitStringLength(cedente.ContaBancaria.DigitoAgencia, 1, 1, '0', 0, true, true, true);
            //_headerLote += Utils.FitStringLength(cedente.ContaBancaria.Conta, 12, 12, '0', 0, true, true, true);
            _headerLote += Utils.FitStringLength(cedente.ContaBancaria.Conta, 13, 13, '0', 0, true, true, true);
            _headerLote += Utils.FitStringLength(cedente.ContaBancaria.DigitoConta, 1, 1, '0', 0, true, true, true);
            //_headerLote += " ";
            _headerLote += Utils.FitStringLength(cedente.Nome, 30, 30, ' ', 0, true, true, false);
            _headerLote += new string(' ', 40);
            _headerLote += new string(' ', 40);
            _headerLote += numeroArquivoRemessa.ToString("00000000");
            _headerLote += DateTime.Now.ToString("ddMMyyyy");
            _headerLote += new string(' ', 8);
            //_headerLote += new string(' ', 33);
            _headerLote += new string('0', 2);
            _headerLote += new string(' ', 31);
            return(_headerLote);
        }
예제 #2
0
        public string GerarHeaderRemessaCNAB400(int numeroConvenio, Cedente cedente, int numeroArquivoRemessa)
        {
            try
            {
                string complemento = new string(' ', 277);
                string _header;

                _header  = "01REMESSA01COBRANCA       ";
                _header += Utils.FitStringLength(cedente.Codigo.ToString(), 20, 20, '0', 0, true, true, true);
                _header += Utils.FitStringLength(cedente.Nome, 30, 30, ' ', 0, true, true, false).ToUpper();
                _header += "084";
                _header += "UNIPRIME       ";
                _header += DateTime.Now.ToString("ddMMyy");
                _header += "        ";
                _header += "MX";
                _header += Utils.FitStringLength(numeroArquivoRemessa.ToString(), 7, 7, '0', 0, true, true, true);
                _header += complemento;
                _header += "000001";

                _header = Utils.SubstituiCaracteresEspeciais(_header);

                return(_header);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar HEADER do arquivo de remessa do CNAB400.", ex);
            }
        }
예제 #3
0
        private string GerarHeaderRemessaCNAB400(string convenio)
        {
            var header = new StringBuilder();

            header.Append("0");             // Identificação do registro header, sempre 0
            header.Append("1");             // Código da remessa, sempre 1
            header.Append("REMESSA");       // Literal de remessa
            header.Append("01");            // Código do serviço, sempre 01
            header.Append(Utils.FitStringLength("COBRANCA", 15, 15, ' ', 0, true, true, false));

            // Identificação por extenso do tipo de serviço
            header.Append(Utils.FitStringLength(convenio, 12, 12, ' ', 0, true, true, false));

            // Código da empresa, fornecido pelo banco
            header.Append(new string(' ', 8));                                                          // BRANCOS
            header.Append(Utils.FitStringLength(this.Cedente.Nome, 30, 30, ' ', 0, true, true, false)); // Nome do cedente
            header.Append("707");                                                                       // Código do banco
            header.Append(Utils.FitStringLength("BANCO DAYCOVAL", 15, 15, ' ', 0, true, true, false));  // Nome do banco
            header.Append(DateTime.Now.ToString("ddMMyy"));                                             // Data
            header.Append(Utils.FitStringLength(string.Empty, 294, 294, ' ', 0, true, true, false));
            header.Append("000001");                                                                    // Sequencial, sempre 1

            var headerFormatado = Utils.SubstituiCaracteresEspeciais(header.ToString());

            return(headerFormatado);
        }
예제 #4
0
        public string GerarRegistroDetalhe2(Boleto boleto, int numeroRegistro)
        {
            string _detalhe = "";

            _detalhe += "2";                                     // 001 a 001 Tipo Registro
            _detalhe += new string(' ', 320);                    // 002 a 321 Mensagens 1,2,3,4
            if (boleto.DataOutrosDescontos == DateTime.MinValue) // 322 a 327 Data limite para concessão de Desconto 2
            {
                _detalhe += "000000";                            //Caso nao tenha data de vencimento
            }
            else
            {
                _detalhe += boleto.DataOutrosDescontos.ToString("ddMMyy");
            }

            // 328 a 340 Valor do Desconto 2
            _detalhe += Utils.FitStringLength(boleto.OutrosDescontos.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true);
            _detalhe += "000000"; // 341 a 346 ata limite para concessão de Desconto 3
            // 347 a 359 Valor do Desconto 3
            _detalhe += Utils.FitStringLength("", 13, 13, '0', 0, true, true, true);
            _detalhe += new string(' ', 7);                                                                                              // 360 a 366 Filler
            _detalhe += Utils.FitStringLength(boleto.Carteira, 3, 3, '0', 0, true, true, true);                                          // 367 a 369  Nº da Carteira
            _detalhe += Utils.FitStringLength(boleto.Cedente.ContaBancaria.Agencia, 5, 5, '0', 0, true, true, true);                     // 370 a 374 N da agencia(5)
            _detalhe += Utils.FitStringLength(boleto.Cedente.ContaBancaria.Conta, 7, 7, '0', 0, true, true, true);                       // 375 a 381 Conta Corrente(7)
            _detalhe += Utils.FitStringLength(boleto.Cedente.ContaBancaria.DigitoConta, 1, 1, '0', 0, true, true, true);                 // 382 a 382 D da conta(1)
            _detalhe += Utils.FitStringLength(boleto.NossoNumero, 11, 11, '0', 0, true, true, true);                                     // 383 a 393 Nosso Número (11)
            // Força o NossoNumero a ter 11 dígitos. Alterado por Luiz Ponce 07/07/2012
            _detalhe += Mod11Deutsche(boleto.Carteira + Utils.FitStringLength(boleto.NossoNumero, 11, 11, '0', 0, true, true, true), 7); // 394 a 394 Digito de Auto Conferencia do Nosso Número (01)
            //Desconto Bonificação por dia (10, N)
            _detalhe += Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true);                                // 395 a 400
            //Retorno
            return(Utils.SubstituiCaracteresEspeciais(_detalhe));
        }
예제 #5
0
        private string GerarHeaderRemessaCNAB400(int numeroConvenio, Cedente cedente, int numeroArquivoRemessa)
        {
            //Variaveis
            StringBuilder _header = new StringBuilder();

            //Tratamento de erros
            try
            {
                //Montagem do header
                _header.Append("0");                                                                                               //Posição 001
                _header.Append("1");                                                                                               //Posição 002
                _header.Append("REMESSA");                                                                                         //Posição 003 a 009
                _header.Append("01");                                                                                              //Posição 010 a 011
                _header.Append("COBRANÇA");                                                                                        //Posição 012 a 019
                _header.Append(new string(' ', 7));                                                                                //Posição 020 a 026
                _header.Append(Utils.FitStringLength(cedente.ContaBancaria.Agencia, 4, 4, '0', 0, true, true, true));              //Posição 027 a 030
                _header.Append(Utils.FitStringLength(cedente.ContaBancaria.DigitoAgencia, 1, 1, '0', 0, true, true, true));        //Posição 031
                _header.Append(Utils.FitStringLength(cedente.Codigo, 8, 8, '0', 0, true, true, true));                             //Posição 032 a 039
                _header.Append(Utils.FitStringLength(Convert.ToString(cedente.DigitoCedente), 1, 1, '0', 0, true, true, true));    //Posição 40
                _header.Append(new string(' ', 6));                                                                                //Posição 041 a 046
                _header.Append(Utils.FitStringLength(cedente.Nome, 30, 30, ' ', 0, true, true, false));                            //Posição 047 a 076
                _header.Append(Utils.FitStringLength("756BANCOOBCED", 18, 18, ' ', 0, true, true, false));                         //Posição 077 a 094
                _header.Append(DateTime.Now.ToString("ddMMyy"));                                                                   //Posição 095 a 100
                _header.Append(Utils.FitStringLength(Convert.ToString(cedente.NumeroSequencial), 7, 7, '0', 0, true, true, true)); //Posição 101 a 107
                _header.Append(new string(' ', 287));                                                                              //Posição 108 a 394
                _header.Append("000001");                                                                                          //Posição 395 a 400

                //Retorno
                return(_header.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar HEADER do arquivo de remessa do CNAB400.", ex);
            }
        }
예제 #6
0
        public string GerarHeaderRemessaCNAB400(int numeroConvenio, Cedente cedente)
        {
            try
            {
                string complemento = new string(' ', 294);
                string _header;

                _header  = "01REMESSA01COBRANCA       ";
                _header += Utils.FitStringLength(cedente.ContaBancaria.Agencia, 4, 4, '0', 0, true, true, true);
                _header += "00";
                _header += Utils.FitStringLength(cedente.ContaBancaria.Conta, 5, 5, '0', 0, true, true, true);
                _header += Utils.FitStringLength(cedente.ContaBancaria.DigitoConta, 1, 1, ' ', 0, true, true, false);
                _header += "        ";
                _header += Utils.FitStringLength(cedente.Nome, 30, 30, ' ', 0, true, true, false).ToUpper();
                _header += "033";
                _header += "BANCO SANTANDER  ";
                _header += DateTime.Now.ToString("ddMMyy");
                _header += complemento;
                _header += "000001";

                _header = Utils.SubstituiCaracteresEspeciais(_header);

                return(_header);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar HEADER do arquivo de remessa do CNAB400.", ex);
            }
        }
예제 #7
0
        public string GerarHeaderRemessaCNAB400(int numeroConvenio, Cedente cedente)
        {
            try
            {
                string complemento = new string(' ', 275);
                string _header;

                _header = "01REMESSA01COBRANCA       ";         //fixo
                //Código da transmissão fornecido pelo banco 9(20), mas normalmente é formado por:
                //018-021 = Código da agencia 9(04)
                //022-029 = Código do cedente 9(08)
                //030-037 = Conta cobrança/corrente 9(08)
                _header += Utils.FitStringLength(cedente.ContaBancaria.Agencia.ToString(), 4, 4, '0', 0, true, true, true);
                _header += Utils.FitStringLength(cedente.Codigo.ToString(), 8, 8, '0', 0, true, true, true);
                _header += Utils.FitStringLength(cedente.ContaBancaria.Conta.ToString(), 8, 8, '0', 0, true, true, true);
                _header += Utils.FitStringLength(cedente.Nome.ToString(), 30, 30, ' ', 0, true, true, false).ToUpper();
                _header += "033";
                _header += "SANTANDER      ";                   //Nome do banco X(15)
                _header += DateTime.Now.ToString("ddMMyy");     //data da gravação
                _header += "0000000000000000";                  //zeros 9(16)
                _header += complemento;                         //brancos X(275)
                _header += "000";                               //zeros 9(03)
                _header += "000001";

                _header = Utils.SubstituiCaracteresEspeciais(_header);

                return(_header);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar HEADER do arquivo de remessa do CNAB400.", ex);
            }
        }
예제 #8
0
 public override void FormataNumeroDocumento(Boleto boleto)
 {
     //throw new NotImplementedException("Função não implementada.");
     boleto.Cedente.ContaBancaria.Agencia       = Utils.FitStringLength(boleto.Cedente.ContaBancaria.Agencia, 5, 5, '0', 0, true, true, true);
     boleto.Cedente.ContaBancaria.Conta         = Utils.FitStringLength(boleto.Cedente.ContaBancaria.Conta, 8, 8, '0', 0, true, true, true);
     boleto.Cedente.ContaBancaria.Conta        += boleto.Cedente.ContaBancaria.DigitoConta;
     boleto.Cedente.ContaBancaria.DigitoAgencia = ""; boleto.Cedente.ContaBancaria.DigitoConta = "";
     boleto.Cedente.Nome += " " + boleto.Cedente.CPFCNPJ;
 }
예제 #9
0
        /// <summary>
        /// Retorna o Header do arquivo Remessa conforme Layout Padrão Febraban 240 posições V10.3.
        /// </summary>
        /// <seealso cref="http://www.febraban.org.br"/>
        /// <returns></returns>
        private string GerarHeaderRemessaCNAB240(int numeroConvenio, Cedente cedente, int numeroArquivoRemessa)
        {
            try
            {
                StringBuilder header = new StringBuilder(240);
                // Código do Banco na compensação
                header.Append(Codigo.ToString("D3"));
                // Lote de Serviço
                header.Append("0000");
                // tipo de Registro
                header.Append("0");
                // Brancos
                header.AppendFormat("{0,9}", " ");
                // Tipo de Inscrição da Empresa
                header.Append((cedente.CPFCNPJ.Length == 11 ? "1" : "2"));
                // Número de Inscrição da Empresa
                header.Append(Utils.FormatCode(cedente.CPFCNPJ, "0", 14, true));
                // Código do Convênio no Banco
                header.Append(Utils.FormatCode(numeroConvenio.ToString(), " ", 20));

                // Agencia e Conta
                header.Append(ContaBancariaFormatada(cedente));

                // Dígito Verificador da Ag/Conta
                header.Append(" ");
                // Nome da Empresa
                header.Append(Utils.FitStringLength(cedente.Nome, 30, 30, ' ', 0, true, true, false));
                // Nome do Banco
                header.Append(Utils.FormatCode(Nome, " ", 30));
                // Brancos
                header.AppendFormat("{0,10}", " ");
                // Código Remessa / Retorno: '1' = Remessa (Cliente Banco)
                header.Append("1");
                // Data Hora de Geração do Arquivo.
                header.Append(DateTime.Now.ToString("ddMMyyyyHHmmss"));
                // Número Seqüencial do Arquivo
                header.Append(numeroArquivoRemessa.ToString("D6"));
                // No da Versão do Layout do Arquivo
                header.Append("103");
                // Densidade de Gravação do Arquivo
                header.Append("00000");
                // Para Uso Reservado do Banco / Empresa / FEBRABAN / CNAB
                header.AppendFormat("{0,69}", " ");
                return(Utils.SubstituiCaracteresEspeciais(header.ToString()));
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar HEADER do arquivo de remessa do CNAB240.", ex);
            }
        }
예제 #10
0
        string IBanco.GerarTrailerRemessa(int numeroRegistro, TipoArquivo tipoArquivo, Cedente cedente, decimal vltitulostotal)
        {
            StringBuilder _trailer = new StringBuilder();

            try {
                //Montagem trailer
                _trailer.Append("9");                                                                              //Posição 001
                _trailer.Append(new string(' ', 393));                                                             //Posição 002 a 394
                _trailer.Append(Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true)); //Posição 395 a 400

                //Retorno
                return(Utils.SubstituiCaracteresEspeciais(_trailer.ToString()));
            } catch (Exception ex) {
                throw new Exception("Erro ao gerar TRAILER do arquivo de remessa do CNAB400.", ex);
            }
        }
예제 #11
0
        /// <summary>
        ///	O código de barra para cobrança contém 44 posições dispostas da seguinte forma:
        ///    01 a 03 - 3 - Identificação  do  Banco
        ///    04 a 04 - 1 - Código da Moeda
        ///    05 a 05 – 1 - Dígito verificador do Código de Barras
        ///    06 a 19 - 14 - Valor
        ///    20 a 44 – 25 - Campo Livre
        /// </summary>
        public override void FormataCodigoBarra(Boleto boleto)
        {
            //string valorBoleto = boleto.ValorBoleto.ToString("f").Replace(",", "").Replace(".", "");
            //valorBoleto = Utils.FormatCode(valorBoleto, 14);

            //boleto.CodigoBarra.Codigo = string.Format("{0}{1}{2}{3}{4}", Codigo, boleto.Moeda,
            //        FatorVencimento(boleto), valorBoleto, CampoLivre(boleto));

            //_dacBoleto = 0;
            ////Mod11(Boleto.CodigoBarra.Codigo.Substring(0, 3) + Boleto.CodigoBarra.Codigo.Substring(5, 43), 9, 0);

            //boleto.CodigoBarra.Codigo = Strings.Left(boleto.CodigoBarra.Codigo, 4) + _dacBoleto + Strings.Right(boleto.CodigoBarra.Codigo, 39);

            var banco       = boleto.Banco;
            var codigobarra = boleto.CodigoBarra;

            codigobarra.CampoLivre = CampoLivre(boleto);

            if (codigobarra.CampoLivre.Length != 25)
            {
                throw new Exception("campo livre (" + codigobarra.CampoLivre + ") deve conter 25 dígitos.");
            }

            // formata código de barras do boleto
            codigobarra.CodigoBanco     = Utils.FitStringLength(banco.Codigo.ToString(), 3, 3, '0', 0, true, true, true);
            codigobarra.Moeda           = boleto.Moeda;
            codigobarra.FatorVencimento = FatorVencimento(boleto);
            codigobarra.ValorDocumento  = boleto.ValorBoleto.ToString("n2").Replace(",", "").Replace(".", "").PadLeft(10, '0');


            string codigoSemDv = string.Format("{0}{1}{2}{3}{4}",
                                               codigobarra.CodigoBanco,
                                               codigobarra.Moeda,
                                               codigobarra.FatorVencimento,
                                               codigobarra.ValorDocumento,
                                               codigobarra.CampoLivre);



            boleto.CodigoBarra.Codigo = string.Format("{0}{1}{2}",
                                                      codigoSemDv.Left(4),
                                                      GerarDACBarrasSafra(codigoSemDv),
                                                      codigoSemDv.Right(39));

            //boleto.CodigoBarra.Codigo = Strings.Left(boleto.CodigoBarra.Codigo, 4) + _dacBoleto + Strings.Right(boleto.CodigoBarra.Codigo, 39);
        }
예제 #12
0
        public override string GerarHeaderRemessa(string numeroConvenio, Cedente cedente, TipoArquivo tipoArquivo, int numeroArquivoRemessa)
        {
            try
            {
                string _headerLote;
                _headerLote = "13600000         ";
                if (cedente.CPFCNPJ.Length <= 11)
                {
                    _headerLote += "1";
                }
                else
                {
                    _headerLote += "2";
                }
                _headerLote += Utils.FitStringLength(cedente.CPFCNPJ, 14, 14, '0', 0, true, true, true);
                _headerLote += new string(' ', 20);
                _headerLote += Utils.FitStringLength(cedente.ContaBancaria.Agencia, 5, 5, '0', 0, true, true, true);
                _headerLote += Utils.FitStringLength(cedente.ContaBancaria.DigitoAgencia, 1, 1, '0', 0, true, true, true);
                //_headerLote += Utils.FitStringLength(cedente.ContaBancaria.Conta, 12, 12, '0', 0, true, true, true);
                _headerLote += Utils.FitStringLength(cedente.Codigo, 14, 14, '0', 0, true, true, true);
                //_headerLote += " ";
                _headerLote += Utils.FitStringLength(cedente.Nome, 30, 30, ' ', 0, true, true, false);
                _headerLote += Utils.FitStringLength("UNICRED", 30, 30, ' ', 0, true, true, false);
                _headerLote += new string(' ', 10);
                _headerLote += "1";
                _headerLote += DateTime.Now.ToString("ddMMyyyy");
                //_headerLote += "000000";// DateTime.Now.ToString("HHmmss");
                _headerLote += DateTime.Now.ToString("HHmm") + "00";
                _headerLote += numeroArquivoRemessa.ToString("000000");
                _headerLote += "085";
                _headerLote += "00000";
                //_headerLote += Utils.FitStringLength(cedente.CodigoTransmissao, 3, 3, '0', 0, true, true, true);
                _headerLote += "000";

                _headerLote += new string(' ', 66);
                return(_headerLote);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar HEADER do arquivo de remessa do CNAB400.", ex);
            }
        }
예제 #13
0
        private string GerarTrailerRemessa400(int numeroRegistro)
        {
            try
            {
                var complemento = new string(' ', 393);
                var trailer     = new StringBuilder();

                trailer.Append("9");
                trailer.Append(complemento);
                trailer.Append(Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true));

                // Número sequencial do registro no arquivo.
                var trailerFormatado = Utils.SubstituiCaracteresEspeciais(trailer.ToString());

                return(trailerFormatado);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro durante a geração do registro TRAILER do arquivo de REMESSA.", ex);
            }
        }
예제 #14
0
        public string GerarTrailerRemessa400(int numeroRegistro, decimal vltitulostotal)
        {
            try
            {
                string complemento = new string('0', 374);
                string _trailer;

                _trailer  = "9";
                _trailer += Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true); //Quantidade total de linhas no arquivo
                _trailer += Utils.FitStringLength(vltitulostotal.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true);
                _trailer += complemento;
                _trailer += Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true); // Número sequencial do registro no arquivo.

                _trailer = Utils.SubstituiCaracteresEspeciais(_trailer);

                return(_trailer);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro durante a geração do registro TRAILER do arquivo de REMESSA.", ex);
            }
        }
예제 #15
0
        public override string GerarDetalheSegmentoRRemessa(Boleto boleto, int numeroRegistro, TipoArquivo tipoArquivo)
        {
            try
            {
                string _segmentoR;

                _segmentoR  = "13600013";
                _segmentoR += Utils.FitStringLength(numeroRegistro.ToString(), 5, 5, '0', 0, true, true, true);
                _segmentoR += "R ";
                _segmentoR += ObterCodigoDaOcorrencia(boleto);
                _segmentoR += new string('0', 44);
                _segmentoR += " ";
                _segmentoR += new string('0', 21);
                _segmentoR += new string(' ', 10);

                for (int i = 0; i < 2; i++)
                {
                    if (boleto.Instrucoes.Count > i)
                    {
                        _segmentoR += Utils.FitStringLength(boleto.Instrucoes[i].Descricao, 40, 40, ' ', 0, true, true, false);
                    }
                    else
                    {
                        _segmentoR += new string(' ', 40);
                    }
                }

                _segmentoR += new string(' ', 20);
                _segmentoR += new string('0', 32);
                _segmentoR += new string(' ', 9);
                _segmentoR  = Utils.SubstituiCaracteresEspeciais(_segmentoR);

                return(_segmentoR);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro durante a geração do SEGMENTO R DO DETALHE do arquivo de REMESSA.", ex);
            }
        }
예제 #16
0
        public string GerarRegistroDetalhe5(Boleto boleto, int numeroRegistro, TipoArquivo tipoArquivo)
        {
            StringBuilder detalhe = new StringBuilder();

            switch (tipoArquivo)
            {
            case TipoArquivo.CNAB400:

                detalhe.Append("5");                                                                                                         // 001
                detalhe.Append("99");                                                                                                        // 002-003
                detalhe.Append("2");                                                                                                         // 004 (Percentual)
                detalhe.Append(boleto.DataMulta.ToString("ddMMyy"));                                                                         // 005-010
                detalhe.Append(Utils.FitStringLength(Convert.ToInt32(boleto.PercMulta * 100).ToString(), 12, 12, '0', 1, true, true, true)); // 011-022
                detalhe.Append(new string(' ', 372));                                                                                        // 023 a 394
                detalhe.Append(Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true));                            // 395 a 400

                //Retorno
                return(Utils.SubstituiCaracteresEspeciais(detalhe.ToString()));

            default:
                throw new Exception("Tipo de arquivo não suportado.");
            }
        }
예제 #17
0
        public override string GerarDetalheSegmentoPRemessa(Boleto boleto, int numeroRegistro, string numeroConvenio)
        {
            try
            {
                string _segmentoP;
                //string _nossoNumero;

                _segmentoP  = "136";                                                                                             //Código do Banco na Compensação 1 3 3
                _segmentoP += "0001";                                                                                            //Lote de Serviço 4 7 4
                _segmentoP += "3";                                                                                               //Tipo de Registro 8 8 1
                _segmentoP += Utils.FitStringLength(numeroRegistro.ToString(), 5, 5, '0', 0, true, true, true);                  //Nº Sequencial do Registro no Lote 9 13 5
                _segmentoP += "P ";                                                                                              //Cód. Segmento do Registro Detalhe 14 14 1
                _segmentoP += ObterCodigoDaOcorrencia(boleto);
                _segmentoP += Utils.FitStringLength(boleto.Cedente.ContaBancaria.Agencia, 5, 5, '0', 0, true, true, true);       //Agência Mantenedora da Conta 18 22 5
                _segmentoP += Utils.FitStringLength(boleto.Cedente.ContaBancaria.DigitoAgencia, 1, 1, '0', 0, true, true, true); //Dígito Verificador da Agência 23 23 1
                _segmentoP += Utils.FitStringLength(boleto.Cedente.ContaBancaria.Conta, 12, 12, '0', 0, true, true, true);       //Número da Conta Corrente 24 35 12
                _segmentoP += Utils.FitStringLength(boleto.Cedente.ContaBancaria.DigitoConta, 1, 1, '0', 0, true, true, true);   //Dígito Verificador da Conta 36 36 1
                _segmentoP += "0";                                                                                               //Filler 37 37 1
                //_segmentoP += Utils.FitStringLength(boleto.NossoNumero, 11, 11, ' ', 0, true, true, false); //Identificação do Título no Banco 38 48 11
                _segmentoP += Utils.FitStringLength(boleto.NossoNumero, 10, 10, ' ', 0, true, true, false);
                _segmentoP += Utils.FitStringLength(Mod11UniCred(boleto.NossoNumero.Substring(0, 10)).ToString(), 1, 1, ' ', 0, true, true, false);
                _segmentoP += new string(' ', 8);
                _segmentoP += Utils.FitStringLength(boleto.Carteira, 2, 2, ' ', 0, true, true, false);
                _segmentoP += new string(' ', 4);
                _segmentoP += Utils.FitStringLength(boleto.NumeroDocumento, 15, 15, ' ', 0, true, true, false);
                _segmentoP += Utils.FitStringLength(boleto.DataVencimento.ToString("ddMMyyyy"), 8, 8, ' ', 0, true, true, false);
                _segmentoP += Utils.FitStringLength(boleto.ValorBoleto.ToString("f").Replace(",", "").Replace(".", ""), 15, 15, '0', 0, true, true, true);
                //_segmentoP += new string(' ', 8);
                _segmentoP += new string(' ', 6);
                _segmentoP += "N";
                _segmentoP += new string(' ', 1);
                _segmentoP += "N";
                _segmentoP += Utils.FitStringLength(boleto.DataDocumento.ToString("ddMMyyyy"), 8, 8, ' ', 0, true, true, false);

                if (boleto.JurosMora > 0)
                {
                    _segmentoP += "1";
                    _segmentoP += "00000000";
                    _segmentoP += Utils.FitStringLength(boleto.JurosMora.ApenasNumeros(), 15, 15, '0', 0, true, true, true);
                }
                else
                {
                    _segmentoP += "5";
                    //_segmentoP += "00000000";
                    //_segmentoP += "000000000000000";
                    _segmentoP += new string(' ', 8);  //Filler 119 126 8
                    _segmentoP += new string('0', 15); //Juros de Mora por Dia/Taxa 127 141 15
                }

                if (boleto.ValorDesconto > 0)
                {
                    _segmentoP += "1";
                    _segmentoP +=
                        Utils.FitStringLength(
                            boleto.DataDesconto == DateTime.MinValue
                                ? boleto.DataVencimento.ToString("ddMMyyyy")
                                : boleto.DataDesconto.ToString("ddMMyyyy"), 8, 8, '0', 0, true, true, false);
                    _segmentoP += Utils.FitStringLength(boleto.ValorDesconto.ApenasNumeros(), 15, 15, '0', 0, true, true, true);
                }
                else
                {
                    _segmentoP += "000000000000000000000000";
                }

                //_segmentoP += "000000000000000";
                //_segmentoP += "000000000000000";
                _segmentoP += new string(' ', 15);                                                                                       //Filler 166 180 15 Alfa
                _segmentoP += new string('0', 15);                                                                                       //Valor do Abatimento 181 195 15 Num

                _segmentoP += Utils.FitStringLength(boleto.NumeroControle ?? boleto.NumeroDocumento, 25, 25, ' ', 0, true, true, false); //alterado por diegodariolli - 15/03/2018 //Identificação do Título na Empresa 196 220 25 - Alfa
                //_segmentoP += " ";
                //_segmentoP += "  ";
                _segmentoP += new string('0', 1);  //Código para Protesto 221 221 1 - Num Zeros
                //_segmentoP += "0";
                _segmentoP += new string('0', 2);  //Número de Dias para Protesto 222 223 2 - Num
                //_segmentoP += "   ";
                _segmentoP += new string(' ', 4);  //Filler 224 227 4 - Alfa
                //_segmentoP += "  ";
                _segmentoP += "09";                //Código da Moeda 228 229 2 - Num
                //_segmentoP += "0000000000";
                _segmentoP += new string('0', 10); //Nº do Contrato da Operação de Créd. 230 239 10 - Num
                _segmentoP += " ";                 //Uso Exclusivo FEBRABAN/CNAB 240 240 1 - Alfa
                _segmentoP  = Utils.SubstituiCaracteresEspeciais(_segmentoP.ToUpper());
                return(_segmentoP);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro durante a geração do SEGMENTO P DO DETALHE do arquivo de REMESSA.", ex);
            }
        }
예제 #18
0
 /// <summary>
 /// Calcula o digito do Nosso Numero
 /// </summary>
 public string CalcularDigitoNossoNumero(Boleto boleto)
 {
     return(Mod11Uniprime(boleto.Carteira + Utils.FitStringLength(boleto.NossoNumero, 11, 11, '0', 0, true, true, true), 7));
 }
예제 #19
0
        public string GerarDetalheRemessaCNAB400(Boleto boleto, int numeroRegistro, TipoArquivo tipoArquivo)
        {
            try
            {
                base.GerarDetalheRemessa(boleto, numeroRegistro, tipoArquivo);

                string controle_partic = new string(' ', 25);
                string sacador_aval    = new string(' ', 30);
                string _detalhe;

                _detalhe = "1";

                // Tipo de inscrição do cedente
                // 01 - CPF DO CEDENTE
                // 02 - CNPJ DO CEDENTE

                if (boleto.Cedente.CPFCNPJ.Length <= 11)
                {
                    _detalhe += "01";
                }
                else
                {
                    _detalhe += "02";
                }

                _detalhe += Utils.FitStringLength(boleto.Cedente.CPFCNPJ.ToString(), 14, 14, '0', 0, true, true, true);
                //Código da transmissão fornecido pelo banco 9(20), mas normalmente é formado por:
                //018-021 = Código da agencia 9(04)
                //022-029 = Código do cedente 9(08)
                //030-037 = Conta cobrança/corrente 9(08)
                _detalhe += Utils.FitStringLength(boleto.Cedente.ContaBancaria.Agencia.ToString(), 4, 4, '0', 0, true, true, true);
                _detalhe += Utils.FitStringLength(boleto.Cedente.Codigo.ToString(), 8, 8, '0', 0, true, true, true);
                _detalhe += Utils.FitStringLength(boleto.Cedente.ContaBancaria.Conta.ToString(), 8, 8, '0', 0, true, true, true);
                //Número de controle do participante, controle do cedente X(25)
                _detalhe += controle_partic;
                //NossoNumero com DV, pegar os 8 primeiros dígitos, da direita para esquerda
                string nossoNumero = Utils.FormatCode(boleto.NossoNumero, 12) + Mod11Santander(Utils.FormatCode(boleto.NossoNumero, 12), 9); //13
                _detalhe += Utils.Right(nossoNumero, 8, '0', true);
                _detalhe += "000000";                                                                                                        //Data do segundo desconto 9(06)
                _detalhe += " ";                                                                                                             //brancos X(01)
                //(Nota 4) posição 78-78, sempre igual a '4', sendo obrigatório a informação do percentual na posição 79-82
                _detalhe += "4";
                //Percentual de multa por atraso 9(04)V99 = significa 4 posições, sendo 2 decimais
                _detalhe += Utils.FitStringLength(boleto.PercMulta.ToString("0.00").Replace(",", ""), 4, 4, '0', 0, true, true, true);
                _detalhe += "00";            //Unidade de valor mora corrente = 00
                _detalhe += "0000000000000"; //Valor do titulo em outra unidade (consultar banco) 9(13)V99 = significa 13 posições, sendo 2 decimais
                _detalhe += "    ";          //brancos X(04)
                _detalhe += "000000";        //Data de cobrança da multa, se zeros, será cobrada após vencimento

                //Código da carteira
                //1 - Eletrônica COM registro
                //3 - Caucionada eletrônica
                //4 - Cobrança SEM registro
                //5 - Rápida COM registro
                //6 - Caucionada rápida
                //7 - Descontada eletrônica
                _detalhe += "5";

                //Código de ocorrência
                //01 - Entrada de título
                //02 - Baixa de título
                //04 - Concessão de abatimento
                //05 - Cancelamento de abatimento
                //06 - Prorrogação de vencimento
                //07 - Alteração número de controle do cedente
                //08 - Alteração do seu número
                //09 - Protestar
                //18 - Sustar protesto
                _detalhe += "01";

                //Nº do documento
                _detalhe += Utils.FitStringLength(boleto.NumeroDocumento, 10, 10, ' ', 0, true, true, false);
                _detalhe += boleto.DataVencimento.ToString("ddMMyy");
                _detalhe += Utils.FitStringLength(boleto.ValorBoleto.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true);
                _detalhe += "033";

                //Se a código da carteira = 5 (Rápida COM registro), informar, senão = 00000 (zeros 9(05))
                _detalhe += Utils.FitStringLength(boleto.Cedente.ContaBancaria.Agencia.ToString(), 4, 4, '0', 0, true, true, true);
                _detalhe += Utils.FitStringLength(boleto.Cedente.ContaBancaria.DigitoAgencia.ToString(), 1, 1, '0', 0, true, true, true);

                //Espécie de documento
                //01 - Duplicata
                //02 - Nota promissória
                //04 - Apólice / Nota Seguro
                //05 - Recibo
                //06 - Duplicata de serviço
                //07 - Letra de cambio

                string especie_doc = "00";

                //Transcrição para arquivo REMESSA. Verifica qual espécie de documento (Ver EspecieDocumento_Santander.cs)
                switch (boleto.EspecieDocumento.Codigo)
                {
                case 2:     //DuplicataMercantil,
                    especie_doc = "01";
                    break;

                case 12:     //NotaPromissoria
                case 13:     //NotaPromissoriaRural
                case 98:     //NotaPromissoariaDireta
                    especie_doc = "02";
                    break;

                case 20:     //ApoliceSeguro
                    especie_doc = "03";
                    break;

                case 17:     //Recibo
                    especie_doc = "05";
                    break;

                case 06:     //DuplicataServico
                    especie_doc = "06";
                    break;

                case 07:     //LetraCambio353
                case 30:     //LetraCambio008
                    especie_doc = "07";
                    break;

                default:        //Cheque ou qualquer outro código
                    especie_doc = "01";
                    break;
                }

                _detalhe += especie_doc;
                _detalhe += "N"; // Identificação de título, Aceito ou Não aceito

                //A data informada neste campo deve ser a mesma data de emissão do título de crédito
                //(Duplicata de Serviço / Duplicata Mercantil / Nota Fiscal, etc), que deu origem a esta Cobrança.
                //Existindo divergência, na existência de protesto, a documentação poderá não ser aceita pelo Cartório.
                _detalhe += boleto.DataDocumento.ToString("ddMMyy");

                switch (boleto.Instrucoes.Count)
                {
                case 0:
                    _detalhe += "0000";     //Não há instruções
                    break;

                case 1:
                    _detalhe += Utils.FitStringLength(boleto.Instrucoes[0].Codigo.ToString(), 2, 2, '0', 0, true, true, true);
                    _detalhe += "00";
                    break;

                default:
                    _detalhe += Utils.FitStringLength(boleto.Instrucoes[0].Codigo.ToString(), 2, 2, '0', 0, true, true, true);
                    _detalhe += Utils.FitStringLength(boleto.Instrucoes[1].Codigo.ToString(), 2, 2, '0', 0, true, true, true);
                    break;
                }

                //Valor de mora cobrado por dia de atraso (Juros de 1 dia)
                _detalhe += Utils.FitStringLength(boleto.JurosMora.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true);

                // Data limite para desconto
                _detalhe += boleto.DataVencimento.ToString("ddMMyy");
                _detalhe += Utils.FitStringLength(boleto.ValorDesconto.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true);
                _detalhe += "0000000000000"; // Valor do IOF a ser recolhido pelo banco para Nota de Seguro 9(13)V9(02) = significa 13 posições, sendo 2 decimais
                _detalhe += "0000000000000"; // Valor do Abatimento 9(13)V9(02) = significa 13 posições, sendo 2 decimais

                if (boleto.Sacado.CPFCNPJ.Length <= 11)
                {
                    _detalhe += "01";  // CPF
                }
                else
                {
                    _detalhe += "02"; // CNPJ
                }
                _detalhe += Utils.FitStringLength(boleto.Sacado.CPFCNPJ, 14, 14, '0', 0, true, true, true).ToUpper();
                _detalhe += Utils.FitStringLength(boleto.Sacado.Nome.TrimStart(' '), 40, 40, ' ', 0, true, true, false).ToUpper();
                _detalhe += Utils.FitStringLength(boleto.Sacado.Endereco.End.TrimStart(' '), 40, 40, ' ', 0, true, true, false).ToUpper();
                _detalhe += Utils.FitStringLength(boleto.Sacado.Endereco.Bairro.TrimStart(' '), 12, 12, ' ', 0, true, true, false).ToUpper();
                _detalhe += Utils.FitStringLength(boleto.Sacado.Endereco.CEP, 8, 8, ' ', 0, true, true, true);
                _detalhe += Utils.FitStringLength(boleto.Sacado.Endereco.Cidade.TrimStart(' '), 15, 15, ' ', 0, true, true, false).ToUpper();
                _detalhe += Utils.FitStringLength(boleto.Sacado.Endereco.UF, 2, 2, ' ', 0, true, true, false).ToUpper();

                //Nome do Sacador ou coobrigado
                _detalhe += sacador_aval;
                _detalhe += " "; //brancos X(01)
                // Identificador de complemento de conta cobrança
                _detalhe += "I";
                //Complemento da conta, posições 384-385, com a última posição da conta e o dígito da conta
                _detalhe += boleto.Cedente.ContaBancaria.Conta.Substring(boleto.Cedente.ContaBancaria.Conta.Length - 1, 1) + boleto.Cedente.ContaBancaria.DigitoConta;
                _detalhe += "      "; //brancos X(06)
                _detalhe += "00";     //Nº de dias para protesto 9(02)
                _detalhe += " ";      //brancos X(01)
                _detalhe += Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true);

                _detalhe = Utils.SubstituiCaracteresEspeciais(_detalhe);

                return(_detalhe);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar DETALHE do arquivo CNAB400.", ex);
            }
        }
예제 #20
0
        private string GerarDetalheRemessaCNAB400(Boleto boleto, int numeroRegistro, TipoArquivo tipoArquivo)
        {
            //Variaveis
            var _detalhe = new StringBuilder();

            //Tratamento de erros
            try
            {
                //Montagem do Detalhe
                _detalhe.Append("1");                                                                                                                                              //Posição 001
                _detalhe.Append(Utils.IdentificaTipoInscricaoSacado(boleto.Cedente.CPFCNPJ));                                                                                      //Posição 002 a 003
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.CPFCNPJ.Replace(".", "").Replace("-", "").Replace("/", ""), 14, 14, '0', 0, true, true, true));               //Posição 004 a 017
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.ContaBancaria.Agencia, 4, 4, '0', 0, true, true, true));                                                      //Posição 018 a 021
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.ContaBancaria.DigitoAgencia, 1, 1, '0', 0, true, true, true));                                                //Posição 022
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.ContaBancaria.Conta, 8, 8, '0', 0, true, true, true));                                                        //Posição 023 a 030
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.ContaBancaria.DigitoConta, 1, 1, '0', 0, true, true, true));                                                  //Posição 031
                _detalhe.Append(new string('0', 6));                                                                                                                               //Posição 032 a 037
                _detalhe.Append(Utils.FitStringLength(boleto.NumeroDocumento, 25, 25, ' ', 0, true, true, false));                                                                 //Posição 038 a 62
                _detalhe.Append(Utils.FitStringLength(FormataNumeroTitulo(boleto), 12, 12, '0', 0, true, true, true));                                                             //Posição 063 a 074
                _detalhe.Append(Utils.FitStringLength(boleto.NumeroParcela.ToString(), 2, 2, '0', 0, true, true, true));                                                           //Posição 075 a 076
                _detalhe.Append("00");                                                                                                                                             //Posição 077 a 078
                _detalhe.Append("   ");                                                                                                                                            //Posição 079 a 081
                _detalhe.Append(" ");                                                                                                                                              //Posição 082
                _detalhe.Append("   ");                                                                                                                                            //Posição 083 a 085
                _detalhe.Append("000");                                                                                                                                            //Posição 086 a 088
                _detalhe.Append("0");                                                                                                                                              //Posição 089
                _detalhe.Append("00000");                                                                                                                                          //Posição 090 a 094
                _detalhe.Append("0");                                                                                                                                              //Posição 095
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.NumeroBordero.ToString(), 6, 6, '0', 0, true, true, true));                                                   //Posição 096 a 101
                _detalhe.Append(new string(' ', 5));                                                                                                                               //Posição 102 a 106
                _detalhe.Append(Utils.FitStringLength(boleto.Carteira, 2, 2, '0', 0, true, true, true));                                                                           //Posição 107 a 108
                _detalhe.Append("01");                                                                                                                                             //Posição 109 a 110 - REGISTRO DE TITULOS
                _detalhe.Append(Utils.FitStringLength(boleto.NumeroDocumento, 10, 10, '0', 0, true, true, true));                                                                  //Posição 111 a 120
                _detalhe.Append(boleto.DataVencimento.ToString("ddMMyy"));                                                                                                         //Posição 121 a 126
                _detalhe.Append(Utils.FitStringLength(boleto.ValorBoleto.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true));                                    //Posição 127 a 139
                _detalhe.Append(boleto.Banco.Codigo);                                                                                                                              //Posição 140 a 142
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.ContaBancaria.Agencia, 4, 4, '0', 0, true, true, true));                                                      //Posição 143 a 146
                _detalhe.Append(Utils.FitStringLength(boleto.Cedente.ContaBancaria.DigitoAgencia, 1, 1, '0', 0, true, true, true));                                                //Posição 147
                _detalhe.Append(boleto.EspecieDocumento.Codigo);                                                                                                                   //Posição 148 a 149
                _detalhe.Append(boleto.Aceite == "N" ? "0" : "1");                                                                                                                 //Posição 150
                _detalhe.Append(boleto.DataProcessamento.ToString("ddMMyy"));                                                                                                      //Posição 151 a 156
                _detalhe.Append("07");                                                                                                                                             //Posição 157 a 158 - NÂO PROTESTAR
                _detalhe.Append("22");                                                                                                                                             //Posição 159 a 160 - PERMITIR DESCONTO SOMENTE ATE DATA ESTIPULADA
                _detalhe.Append(Utils.FitStringLength(Convert.ToInt32(boleto.PercJurosMora * 10000).ToString(), 6, 6, '0', 1, true, true, true));                                  //Posição 161 a 166
                _detalhe.Append(Utils.FitStringLength(Convert.ToInt32(boleto.PercMulta * 10000).ToString(), 6, 6, '0', 1, true, true, true));                                      //Posição 167 a 172
                _detalhe.Append(" ");                                                                                                                                              //Posição 173
                _detalhe.Append(Utils.FitStringLength((boleto.DataDesconto == DateTime.MinValue ? "0" : boleto.DataDesconto.ToString("ddMMyy")), 6, 6, '0', 0, true, true, true)); //Posição 174 a 179
                _detalhe.Append(Utils.FitStringLength(boleto.ValorDesconto.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true));                                  //Posição 180 a 192
                _detalhe.Append("9" + Utils.FitStringLength(boleto.IOF.ToString("0.00").Replace(",", ""), 12, 12, '0', 0, true, true, true));                                      //Posição 193 a 205
                _detalhe.Append(Utils.FitStringLength(boleto.Abatimento.ToString("0.00").Replace(",", ""), 13, 13, '0', 0, true, true, true));                                     //Posição 206 a 218
                _detalhe.Append(Utils.IdentificaTipoInscricaoSacado(boleto.Sacado.CPFCNPJ));                                                                                       //Posição 219 a 220
                _detalhe.Append(Utils.FitStringLength(boleto.Sacado.CPFCNPJ.Replace(".", "").Replace("-", "").Replace("/", ""), 14, 14, '0', 0, true, true, true));                //Posição 221 a 234
                _detalhe.Append(Utils.FitStringLength(boleto.Sacado.Nome, 40, 40, ' ', 0, true, true, false));                                                                     //Posição 235 a 274
                _detalhe.Append(Utils.FitStringLength(boleto.Sacado.Endereco.End, 37, 37, ' ', 0, true, true, false));                                                             //Posição 275 a 311
                _detalhe.Append(Utils.FitStringLength(boleto.Sacado.Endereco.Bairro, 15, 15, ' ', 0, true, true, false));                                                          //Posição 312 a 326
                _detalhe.Append(Utils.FitStringLength(boleto.Sacado.Endereco.CEP, 8, 8, '0', 0, true, true, true));                                                                //Posição 327 a 334
                _detalhe.Append(Utils.FitStringLength(boleto.Sacado.Endereco.Cidade, 15, 15, ' ', 0, true, true, false));                                                          //Posição 335 a 349
                _detalhe.Append(boleto.Sacado.Endereco.UF);                                                                                                                        //Posição 350 a 351
                _detalhe.Append(new string(' ', 40));                                                                                                                              //Posição 352 a 391 - OBSERVACOES
                _detalhe.Append("00");                                                                                                                                             //Posição 392 a 393 - DIAS PARA PROTESTO
                _detalhe.Append(" ");                                                                                                                                              //Posição 394
                _detalhe.Append(Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true));                                                                 //Posição 394 a 400

                //Retorno
                return(Utils.SubstituiCaracteresEspeciais(_detalhe.ToString()));
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gerar DETALHE do arquivo de remessa do CNAB400.", ex);
            }
        }
예제 #21
0
 /// <summary>
 /// Calcula o digito do Nosso Numero
 /// </summary>
 public string CalcularDigitoNossoNumero(Boleto boleto)
 {
     return(Mod11Deutsche(Utils.FitStringLength(boleto.NossoNumero, 10, 10, '0', 0, true, true, true), 9));
 }
예제 #22
0
        private string GerarDetalheRemessaCNAB400(Boleto boleto, int numeroRegistro)
        {
            var detalhe = new StringBuilder();

            detalhe.Append("1");             // Identificação do registro, sempre 1

            // Identificação do tipo de inscrição da empresa
            // 01 - CPF do cedente
            // 02 - CNPJ do cedente
            // 03 - CPF do Sacador
            // 04 - CNPJ Sacador
            detalhe.Append(boleto.Cedente.CPFCNPJ.Length == 11 ? "01" : "02");

            // CPF/CNPJ da empresa ou sacador
            detalhe.Append(Utils.FitStringLength(boleto.Cedente.CPFCNPJ, 14, 14, '0', 0, true, true, true));

            detalhe.Append(Utils.FitStringLength(boleto.Cedente.Convenio.ToString(), 20, 20, ' ', 0, true, true, false));

            // Código da empresea, fornecido pelo banco
            detalhe.Append(Utils.FitStringLength(boleto.NumeroDocumento, 25, 25, ' ', 0, true, true, true));

            detalhe.Append(Utils.FitStringLength(boleto.NossoNumero, 8, 8, '0', 0, true, true, true)); // Nosso número
            detalhe.Append(Utils.FitStringLength(boleto.NossoNumero, 13, 13, '0', 0, true, true, true));

            // Nosso número do correspondente, mesmo do boleto
            if (this._banco == null)
            {
                this._banco = boleto.Banco;
            }

            this._banco.ValidaBoleto(boleto);

            detalhe.Append(Utils.FitStringLength(string.Empty, 24, 24, ' ', 0, true, true, false));           // Uso do banco
            detalhe.Append("4");                                                                              // TODO: Código de remessa
            detalhe.Append("01");                                                                             // TODO: Código de ocorrência
            detalhe.Append(Utils.FitStringLength(boleto.NumeroDocumento, 10, 10, ' ', 0, true, true, false)); // Seu número
            detalhe.Append(boleto.DataVencimento.ToString("ddMMyy"));
            detalhe.Append(Utils.FitStringLength(boleto.ValorBoleto.ApenasNumeros(), 13, 13, '0', 0, true, true, true));
            detalhe.Append("707");                                                               // Código do banco
            detalhe.Append(Utils.FitStringLength(string.Empty, 4, 4, '0', 0, true, true, true)); // Agência cobradora
            detalhe.Append("0");                                                                 // DAC da agência cobradora
            detalhe.Append(Utils.FitStringLength(boleto.EspecieDocumento.Codigo, 2, 2, '0', 0, true, true, true));
            detalhe.Append("N");                                                                 // Indicação de aceite do título, sempre N
            detalhe.Append(boleto.DataDocumento.ToString("ddMMyy"));
            detalhe.Append(Utils.FitStringLength(string.Empty, 4, 4, '0', 0, true, true, true)); // Zeros
            // detalhe.Append(Utils.FitStringLength(boleto.JurosMora.ApenasNumeros(), 13, 13, '0', 0, true, true, true));
            detalhe.Append(Utils.FitStringLength("0", 13, 13, '0', 0, true, true, true));
            detalhe.Append(boleto.DataDesconto == DateTime.MinValue ? "000000" : boleto.DataDesconto.ToString("ddMMyy"));
            detalhe.Append(Utils.FitStringLength(boleto.ValorDesconto.ApenasNumeros(), 13, 13, '0', 0, true, true, true));
            detalhe.Append(Utils.FitStringLength(boleto.IOF.ApenasNumeros(), 26, 26, '0', 0, true, true, true));
            detalhe.Append(boleto.Sacado.CPFCNPJ.Length == 11 ? "01" : "02");
            detalhe.Append(Utils.FitStringLength(boleto.Sacado.CPFCNPJ, 14, 14, '0', 0, true, true, true));
            detalhe.Append(
                Utils.SubstituiCaracteresEspeciais(Utils.FitStringLength(boleto.Sacado.Nome, 30, 30, ' ', 0, true, true, false)));
            detalhe.Append(Utils.FitStringLength(string.Empty, 10, 10, ' ', 0, true, true, false));
            detalhe.Append(
                Utils.SubstituiCaracteresEspeciais(
                    Utils.FitStringLength(boleto.Sacado.Endereco.EndComNumeroEComplemento, 40, 40, ' ', 0, true, true, false)));
            detalhe.Append(
                Utils.SubstituiCaracteresEspeciais(
                    Utils.FitStringLength(boleto.Sacado.Endereco.Bairro, 12, 12, ' ', 0, true, true, false)));
            detalhe.Append(Utils.FitStringLength(boleto.Sacado.Endereco.CEP, 8, 8, '0', 0, true, true, true));
            detalhe.Append(
                Utils.SubstituiCaracteresEspeciais(
                    Utils.FitStringLength(boleto.Sacado.Endereco.Cidade, 15, 15, ' ', 0, true, true, false)));
            detalhe.Append(Utils.FitStringLength(boleto.Sacado.Endereco.UF, 2, 2, ' ', 0, true, true, false));
            if (boleto.Avalista != null)
            {
                detalhe.Append(Utils.FitStringLength(boleto.Avalista.Nome, 30, 30, ' ', 0, true, true, false));
            }
            else
            {
                detalhe.Append(Utils.FitStringLength(string.Empty, 30, 30, ' ', 0, true, true, false));
            }

            detalhe.Append(Utils.FitStringLength(string.Empty, 10, 10, ' ', 0, true, true, false)); // Brancos
            detalhe.Append("00");                                                                   // Dias para início do protesto
            detalhe.Append(boleto.Moeda == 9 ? 0 : 2);
            detalhe.Append(Utils.FitStringLength(numeroRegistro.ToString(), 6, 6, '0', 0, true, true, true));

            var detalheFormatado = detalhe.ToString();

            if (detalheFormatado.Length != 400)
            {
                throw new Exception("Tamanho do registro inválido.");
            }

            return(detalheFormatado);
        }
예제 #23
0
        public override string GerarDetalheSegmentoQRemessa(Boleto boleto, int numeroRegistro, TipoArquivo tipoArquivo)
        {
            try
            {
                string _segmentoQ;

                _segmentoQ  = "13600013";
                _segmentoQ += Utils.FitStringLength(numeroRegistro.ToString(), 5, 5, '0', 0, true, true, true);
                _segmentoQ += "Q ";
                _segmentoQ += ObterCodigoDaOcorrencia(boleto);

                if (boleto.Sacado.CPFCNPJ.Length <= 11)
                {
                    _segmentoQ += "1";
                }
                else
                {
                    _segmentoQ += "2";
                }

                var enderecoSacadoComNumero = boleto.Sacado.Endereco.End;
                if (!string.IsNullOrEmpty(boleto.Sacado.Endereco.Numero))
                {
                    enderecoSacadoComNumero += ", " + boleto.Sacado.Endereco.Numero;
                }

                _segmentoQ += Utils.FitStringLength(boleto.Sacado.CPFCNPJ, 15, 15, '0', 0, true, true, true);
                _segmentoQ += Utils.FitStringLength(boleto.Sacado.Nome.TrimStart(' '), 40, 40, ' ', 0, true, true, false).ToUpper();
                _segmentoQ += Utils.FitStringLength(enderecoSacadoComNumero.TrimStart(' '), 40, 40, ' ', 0, true, true, false).ToUpper();
                _segmentoQ += Utils.FitStringLength(boleto.Sacado.Endereco.Bairro.TrimStart(' '), 15, 15, ' ', 0, true, true, false).ToUpper();
                _segmentoQ += Utils.FitStringLength(boleto.Sacado.Endereco.CEP, 8, 8, ' ', 0, true, true, false).ToUpper();;
                _segmentoQ += Utils.FitStringLength(boleto.Sacado.Endereco.Cidade.TrimStart(' '), 15, 15, ' ', 0, true, true, false).ToUpper();
                _segmentoQ += Utils.FitStringLength(boleto.Sacado.Endereco.UF, 2, 2, ' ', 0, true, true, false).ToUpper();

                if (boleto.Avalista != null)
                {
                    if (boleto.Avalista.CPFCNPJ.Length <= 11)
                    {
                        _segmentoQ += "1";
                    }
                    else
                    {
                        _segmentoQ += "2";
                    }
                    _segmentoQ += Utils.FitStringLength(boleto.Avalista.CPFCNPJ, 15, 15, '0', 0, true, true, true);
                    _segmentoQ += Utils.FitStringLength(boleto.Avalista.Nome, 40, 40, '0', 0, true, true, true);
                }
                else
                {
                    _segmentoQ += "1";
                    _segmentoQ += new string('0', 15);
                    _segmentoQ += new string(' ', 40);
                }
                //_segmentoQ += "000";
                //_segmentoQ += new string(' ', 28);
                _segmentoQ += new string(' ', 31);
                _segmentoQ  = Utils.SubstituiCaracteresEspeciais(_segmentoQ);

                return(_segmentoQ);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro durante a geração do SEGMENTO Q DO DETALHE do arquivo de REMESSA.", ex);
            }
        }
예제 #24
0
 public override void FormataNossoNumero(Boleto boleto)
 {
     //throw new NotImplementedException("Função não implementada.");
     boleto.NossoNumero = Utils.FitStringLength(boleto.NossoNumero, 9, 9, '0', 1, true, true, true);
 }