public RemessaCnab240 GerarRemessa(HeaderRemessaCnab240 header, HeaderLoteRemessaCnab240 headerLote, List <Boleto> boletos, TrailerLoteRemessaCnab240 trailerLote, TrailerRemessaCnab240 trailer) { var objReturn = new RemessaCnab240(); objReturn.Header = header; objReturn.Lotes = new List <LoteRemessaCnab240>(); var ultimoLoteAdicionado = objReturn.AdicionarLote(headerLote, trailerLote); // Usado para identificar com número único e sequencial cada boleto (registro) dentro do lote. var contador = 1; var reg1 = 1; var reg2 = 2; foreach (var boletoAddRemessa in boletos) { objReturn.AdicionarBoletoAoLote(ultimoLoteAdicionado, boletoAddRemessa, contador, reg1, reg2); contador++; reg1 = reg1 + 2; reg2 = reg2 + 2; } objReturn.Trailer = trailer; return(objReturn); }
public string EscreverHeaderDeLote(HeaderLoteRemessaCnab240 infoHeaderLote) { #region NOTAS EXPLICATIVAS HEADER DE LOTE #endregion string nomeCedente = infoHeaderLote.NomeEmpresa; if (nomeCedente.Length > 30) { nomeCedente = infoHeaderLote.NomeEmpresa.Substring(0, 30); } var headerLote = new string(' ', 240); try { headerLote = headerLote.PreencherValorNaLinha(1, 3, "756"); // Código do Banco na Compensação headerLote = headerLote.PreencherValorNaLinha(4, 7, infoHeaderLote.LoteServico.ToString().PadLeft(4, '0')); // Lote de Serviço headerLote = headerLote.PreencherValorNaLinha(8, 8, "1"); // Tipo de Registro headerLote = headerLote.PreencherValorNaLinha(9, 9, "R"); // Tipo de Operação headerLote = headerLote.PreencherValorNaLinha(10, 11, "01"); // Tipo de Serviço headerLote = headerLote.PreencherValorNaLinha(12, 13, string.Empty.PadRight(2, ' ')); // Uso Exclusivo FREBRABAN/CNAB headerLote = headerLote.PreencherValorNaLinha(14, 16, "040"); // Nº da versão do Layout do Lote headerLote = headerLote.PreencherValorNaLinha(17, 17, " "); // Uso Exclusivo FREBRABAN/CNAB headerLote = headerLote.PreencherValorNaLinha(18, 18, infoHeaderLote.NumeroInscricao.Replace(".", "").Replace("/", "").Replace("-", "").Length == 11 ? "1" : "2"); headerLote = headerLote.PreencherValorNaLinha(19, 33, infoHeaderLote.NumeroInscricao.Replace(".", "").Replace("/", "").Replace("-", "").PadLeft(15, '0')); headerLote = headerLote.PreencherValorNaLinha(34, 53, string.Empty.PadLeft(20, ' ')); headerLote = headerLote.PreencherValorNaLinha(54, 58, infoHeaderLote.Agencia.PadLeft(5, '0')); headerLote = headerLote.PreencherValorNaLinha(59, 59, infoHeaderLote.DigitoAgencia); headerLote = headerLote.PreencherValorNaLinha(60, 71, infoHeaderLote.NumeroContaCorrente.PadLeft(12, '0')); headerLote = headerLote.PreencherValorNaLinha(72, 72, infoHeaderLote.DigitoContaCorrente.BoletoBrToStringSafe().PadLeft(1, ' ')); headerLote = headerLote.PreencherValorNaLinha(73, 73, " "); // Uso Exclusivo headerLote = headerLote.PreencherValorNaLinha(74, 103, nomeCedente.PadRight(30, ' ')); // Nome Empresa headerLote = headerLote.PreencherValorNaLinha(104, 143, string.Empty.PadRight(40, ' ')); // Mensagem 1 headerLote = headerLote.PreencherValorNaLinha(144, 183, string.Empty.PadRight(40, ' ')); // Mensagem 2 headerLote = headerLote.PreencherValorNaLinha(184, 191, infoHeaderLote.NumeroRemessaRetorno.PadLeft(8, '0')); // numero remessa headerLote = headerLote.PreencherValorNaLinha(192, 199, DateTime.Now.ToString("ddMMyyyy")); headerLote = headerLote.PreencherValorNaLinha(200, 207, string.Empty.PadLeft(8, '0')); headerLote = headerLote.PreencherValorNaLinha(208, 240, string.Empty.PadRight(33, ' ')); return(headerLote); } catch (Exception e) { throw new Exception( String.Format("<BoletoBr>{0}Falha na geração do HEADER DE LOTE do arquivo de REMESSA.", Environment.NewLine), e); } }
public string EscreverHeaderDeLote(HeaderLoteRemessaCnab240 infoHeaderLote) { #region NOTAS EXPLICATIVAS HEADER DE LOTE #region 04.1 - G028 - TIPO DE OPERAÇÃO /* Tipo de Operação * Código adotado pela FEBRABAN para identificar a transação que será realizada com os registros detalhe do lote. * Domínio: * R = Arquivo Remessa * T = Arquivo Retorno */ #endregion #region 05.1 - G025 - TIPO DE SERVIÇO /* Tipo de Serviço * Código adotado pela FEBRABAN para indicar o tipo de serviço / produto (processo) contido no arquivo / lote. * Domínio: * 01 = Cobrança Registrada * 02 = Cobrança Sem Registro / Serviços * 03 = Desconto de Títulos * 04 = Caução de Títulos */ #endregion #endregion string nomeCedente = infoHeaderLote.NomeEmpresa; if (nomeCedente.Length > 30) { nomeCedente = infoHeaderLote.NomeEmpresa.Substring(0, 30); } var headerLote = new string(' ', 240); try { headerLote = headerLote.PreencherValorNaLinha(1, 3, "104"); // Código do Banco na Compensação headerLote = headerLote.PreencherValorNaLinha(4, 7, infoHeaderLote.LoteServico.ToString().PadLeft(4, '0')); // Lote de Serviço headerLote = headerLote.PreencherValorNaLinha(8, 8, "1"); // Tipo de Registro headerLote = headerLote.PreencherValorNaLinha(9, 9, "R"); /* * // Padronizado para 02 - COBRANÇA SEM REGISTRO * headerLote = headerLote.PreencherValorNaLinha(10, 11, "02"); // Tipo de Serviço */ headerLote = headerLote.PreencherValorNaLinha(10, 11, infoHeaderLote.TipoRegistro.ToString("n0").PadLeft(2, '0')); // Tipo de Serviço headerLote = headerLote.PreencherValorNaLinha(12, 13, "00"); // Uso Exclusivo FREBRABAN/CNAB headerLote = headerLote.PreencherValorNaLinha(14, 16, "030"); // Nº da versão do Layout do Lote headerLote = headerLote.PreencherValorNaLinha(17, 17, " "); // Uso Exclusivo FREBRABAN/CNAB headerLote = headerLote.PreencherValorNaLinha(18, 18, infoHeaderLote.NumeroInscricao.Replace(".", "").Replace("/", "").Replace("-", "").Length == 11 ? "1" : "2"); headerLote = headerLote.PreencherValorNaLinha(19, 33, infoHeaderLote.NumeroInscricao.Replace(".", "").Replace("/", "").Replace("-", "").PadLeft(15, '0')); headerLote = headerLote.PreencherValorNaLinha(34, 39, infoHeaderLote.CodigoCedente.PadLeft(6, '0')); headerLote = headerLote.PreencherValorNaLinha(40, 53, string.Empty.PadLeft(14, '0')); headerLote = headerLote.PreencherValorNaLinha(54, 58, infoHeaderLote.Agencia.PadLeft(5, '0')); headerLote = headerLote.PreencherValorNaLinha(59, 59, infoHeaderLote.DigitoAgencia); headerLote = headerLote.PreencherValorNaLinha(60, 65, infoHeaderLote.CodigoCedente.PadLeft(6, '0')); headerLote = headerLote.PreencherValorNaLinha(66, 72, string.Empty.PadLeft(7, '0')); // Código do Modelo Personalizado headerLote = headerLote.PreencherValorNaLinha(73, 73, "0"); // Uso Exclusivo da CAIXA headerLote = headerLote.PreencherValorNaLinha(74, 103, nomeCedente.PadRight(30, ' ')); headerLote = headerLote.PreencherValorNaLinha(104, 143, string.Empty.PadRight(40, ' ')); // Mensagem 1 headerLote = headerLote.PreencherValorNaLinha(144, 183, string.Empty.PadRight(40, ' ')); // Mensagem 2 headerLote = headerLote.PreencherValorNaLinha(184, 191, infoHeaderLote.NumeroRemessaRetorno.PadLeft(8, '0')); // Número Remessa/Retorno headerLote = headerLote.PreencherValorNaLinha(192, 199, DateTime.Now.ToString("ddMMyyyy")); headerLote = headerLote.PreencherValorNaLinha(200, 207, string.Empty.PadLeft(8, '0')); headerLote = headerLote.PreencherValorNaLinha(208, 240, string.Empty.PadRight(33, ' ')); return(headerLote); } catch (Exception e) { throw new Exception( String.Format("<BoletoBr>{0}Falha na geração do HEADER DE LOTE do arquivo de REMESSA.", Environment.NewLine), e); } }