Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public string EscreverTrailerDeLote(TrailerLoteRemessaCnab240 infoTrailerLote)
        {
            if (infoTrailerLote.QtdRegistrosLote == 0)
            {
                throw new Exception("Sequencial do registro no lote não foi informado na geração do TRAILER DE LOTE.");
            }

            var trailerLote = new string(' ', 240);

            try
            {
                trailerLote = trailerLote.PreencherValorNaLinha(1, 3, "246");
                trailerLote = trailerLote.PreencherValorNaLinha(4, 7, infoTrailerLote.LoteServico.ToString().PadLeft(4, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(8, 8, "5");
                trailerLote = trailerLote.PreencherValorNaLinha(9, 17, string.Empty.PadLeft(9, ' '));
                trailerLote = trailerLote.PreencherValorNaLinha(18, 23, infoTrailerLote.QtdRegistrosLote.ToString().PadLeft(6, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(24, 29, infoTrailerLote.QtdTitulosCobrancaSimples.ToString().PadLeft(6, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(30, 46, infoTrailerLote.ValorTitulosCobrancaSimples.ToStringParaValoresDecimais().PadLeft(17, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(47, 52, string.Empty.PadLeft(6, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(53, 69, string.Empty.PadLeft(17, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(70, 75, infoTrailerLote.QtdTitulosCobrancaCaucionada.ToString().PadLeft(6, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(76, 92, infoTrailerLote.ValorTitulosCobrancaCaucionada.ToStringParaValoresDecimais().PadLeft(17, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(93, 98, infoTrailerLote.QtdTitulosCobrancaDescontada.ToString().PadLeft(6, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(99, 115, infoTrailerLote.ValorTitulosCobrancaDescontada.ToStringParaValoresDecimais().PadLeft(17, '0'));
                trailerLote = trailerLote.PreencherValorNaLinha(116, 123, string.Empty.PadLeft(8, ' '));
                trailerLote = trailerLote.PreencherValorNaLinha(124, 240, string.Empty.PadLeft(117, ' '));

                return(trailerLote);
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("<BoletoBr>{0}Falha na geração do TRAILER DE LOTE do arquivo de REMESSA.",
                                                  Environment.NewLine), e);
            }
        }