public static EspeciesDocumento CarregaTodas() { EspeciesDocumento especiesDocumento = new EspeciesDocumento(); EspecieDocumento_Caixa ed = new EspecieDocumento_Caixa(); foreach (EnumEspecieDocumento_Caixa item in Enum.GetValues(typeof(EnumEspecieDocumento_Caixa))) especiesDocumento.Add(new EspecieDocumento_Caixa(ed.getCodigoEspecieByEnum(item))); return especiesDocumento; }
public static EspeciesDocumento CarregaTodas() { EspeciesDocumento especiesDocumento = new EspeciesDocumento(); EspecieDocumento_Caixa ed = new EspecieDocumento_Caixa(); foreach (EnumEspecieDocumento_Caixa item in Enum.GetValues(typeof(EnumEspecieDocumento_Caixa))) { especiesDocumento.Add(new EspecieDocumento_Caixa(ed.getCodigoEspecieByEnum(item))); } return(especiesDocumento); }
public static EspeciesDocumento CarregaTodas() { try { EspeciesDocumento alEspeciesDocumento = new EspeciesDocumento(); EspecieDocumento_Caixa obj; obj = new EspecieDocumento_Caixa((int)EnumEspecieDocumento_Caixa.DuplicataMercantil); alEspeciesDocumento.Add(obj); return(alEspeciesDocumento); } catch (Exception ex) { throw new Exception("Erro ao listar objetos", ex); } }
protected void Page_Load(object sender, EventArgs e) { DateTime vencimento = DateTime.Now.AddDays(5); Cedente c = new Cedente("000.000.000-00", "Boleto.net ILTDA", "1234", "12345678", "9"); c.Codigo = "112233"; Boleto b = new Boleto(vencimento, 20.00m, "2", "0123456789", c); b.Sacado = new Sacado("000.000.000-00", "Nome do seu Cliente "); b.Sacado.Endereco.End = "Endereço do seu Cliente "; b.Sacado.Endereco.Bairro = "Bairro"; b.Sacado.Endereco.Cidade = "Cidade"; b.Sacado.Endereco.CEP = "00000000"; b.Sacado.Endereco.UF = "UF"; //Adiciona as instruções ao boleto #region Instruções Instrucao_Caixa item; //ImportanciaporDiaDesconto item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.Multa, Convert.ToDecimal(0.40)); b.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.JurosdeMora, Convert.ToDecimal(0.01)); b.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.NaoReceberAposNDias, 90); b.Instrucoes.Add(item); #endregion Instruções EspecieDocumento_Caixa ed = new EspecieDocumento_Caixa(); b.EspecieDocumento = new EspecieDocumento_Caixa(ed.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); b.NumeroDocumento = "00001"; b.DataProcessamento = DateTime.Now; b.DataDocumento = DateTime.Now; boletoBancario.Boleto = b; boletoBancario.Boleto.Valida(); //lblCodigoBarras.Text = b.CodigoBarra.Codigo.ToString(); boletoBancario.MostrarComprovanteEntrega = (Request.Url.Query == "?show"); }
public string Caixa() { DateTime vencimento = new DateTime(2008, 12, 20); Cedente c = new Cedente("000.000.000-00", "Boleto.net ILTDA", "1234", "12345678", "9"); c.Codigo = "112233"; BoletoNet.Boleto b = new BoletoNet.Boleto(vencimento, 20.00m, "2", "0123456789", c); b.Sacado = new Sacado("000.000.000-00", "Nome do seu Cliente "); b.Sacado.Endereco.End = "Endereço do seu Cliente "; b.Sacado.Endereco.Bairro = "Bairro"; b.Sacado.Endereco.Cidade = "Cidade"; b.Sacado.Endereco.CEP = "00000000"; b.Sacado.Endereco.UF = "UF"; //Adiciona as instruções ao boleto #region Instruções Instrucao_Caixa item; //ImportanciaporDiaDesconto item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.Multa, Convert.ToDecimal(0.40)); b.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.JurosdeMora, Convert.ToDecimal(0.01)); b.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.NaoReceberAposNDias, 90); b.Instrucoes.Add(item); #endregion Instruções EspecieDocumento_Caixa espDocCaixa = new EspecieDocumento_Caixa(); b.EspecieDocumento = new EspecieDocumento_Caixa(espDocCaixa.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); b.NumeroDocumento = "00001"; b.DataProcessamento = DateTime.Now; b.DataDocumento = DateTime.Now; boletoBancario.Boleto = b; boletoBancario.Boleto.Valida(); return boletoBancario.MontaHtmlEmbedded(); }
public BoletoBancario montaBoleto(BoletoDados boletoDados) { BoletoBancario boletoBancario = new BoletoBancario(); boletoBancario.CodigoBanco = short.Parse(boletoDados.boletoCodigoDoBanco); Cedente cedente = new Cedente(boletoDados.cedenteCpfCNPJ, boletoDados.cedenteNome, boletoDados.cedenteAgencia, boletoDados.cedenteConta); Boleto boleto = new Boleto(DateTime.Parse(boletoDados.dataDeVencimento), Convert.ToDecimal(boletoDados.boletoValor), boletoDados.boletoCarteira, boletoDados.boletoNossoNumero, cedente); boleto.NumeroDocumento = boletoDados.boletoNumeroDoDocumento; boleto.DataDocumento = DateTime.Parse(boletoDados.dataDoDocumento); boleto.DataProcessamento = DateTime.Parse(boletoDados.dataDeProcessamento); boleto.Sacado = new Sacado(boletoDados.sacadoCpfCnpj, boletoDados.sacadoNome); boleto.Sacado.Endereco.End = boletoDados.sacadoEndereco; boleto.Sacado.Endereco.Bairro = boletoDados.sacadoBairro; boleto.Sacado.Endereco.Cidade = boletoDados.sacadoCidade; boleto.Sacado.Endereco.CEP = boletoDados.sacadoCEP; boleto.Sacado.Endereco.UF = boletoDados.sacadoUF; boletoBancario.Boleto = boleto; boletoBancario.FormatoCarne = boletoDados.flagCarne; if (boletoBancario.CodigoBanco == (short)237) //Banco Bradesco { boletoBancario.MostrarContraApresentacaoNaDataVencimento = false; boletoBancario.MostrarCodigoCarteira = false; boletoBancario.MostrarComprovanteEntrega = true; } else { if(boletoBancario.CodigoBanco == (short)104) //Banco CAIXA { EspecieDocumento_Caixa espDocCaixa = new EspecieDocumento_Caixa(); boleto.EspecieDocumento = new EspecieDocumento_Caixa(espDocCaixa.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); boletoBancario.MostrarComprovanteEntrega = true; } else { if (boletoBancario.CodigoBanco == (short)033) //Banco SANTANDER { //Espécie Documento - [R] Recibo boleto.EspecieDocumento = new EspecieDocumento_Santander("17"); boletoBancario.MostrarCodigoCarteira = true; boletoBancario.MostrarComprovanteEntrega = true; } else { //Banco SICOOB boletoBancario.MostrarCodigoCarteira = false; boletoBancario.MostrarComprovanteEntrega = true; } } } boletoBancario.Boleto.Valida(); return boletoBancario; }
protected void Page_Load(object sender, EventArgs e) { int quantidadeDeParcelas = 4; bool flagCarne = true; if (flagCarne == false) { BoletoBancario boletoBancario = new BoletoBancario(); boletoBancario.CodigoBanco = (short)104; DateTime dataDeVencimento = new DateTime(2015, 09, 30); DateTime dataDoDocumeto = new DateTime(2015, 09, 29); DateTime DataDoProcessamento = new DateTime(2015, 09, 29); Cedente c = new Cedente("17.405.814/0001-09", "Instituto Suporte Educacional Treinamento Especializado", "0773", "997", "9"); c.Codigo = "377306"; Boleto boleto = new Boleto(dataDeVencimento, 5.01m, "SR", "24000000000000002", c); boleto.DataDocumento = dataDoDocumeto; boleto.DataProcessamento = DataDoProcessamento; boleto.Sacado = new Sacado("111.111.111-11", "José"); boleto.Sacado.Endereco.End = "Rua Floriano Peixoto, S/N"; boleto.Sacado.Endereco.Bairro = "Centro"; boleto.Sacado.Endereco.Cidade = "Campina Grande"; boleto.Sacado.Endereco.CEP = "58100-000"; boleto.Sacado.Endereco.UF = "PB"; /* //Adiciona as instruções ao boleto #region Instruções Instrucao_Caixa item; //ImportanciaporDiaDesconto item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.Multa, Convert.ToDecimal(0.40)); boleto.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.JurosdeMora, Convert.ToDecimal(0.01)); boleto.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.NaoReceberAposNDias, 90); boleto.Instrucoes.Add(item); #endregion Instruções */ EspecieDocumento_Caixa espDocCaixa = new EspecieDocumento_Caixa(); boleto.EspecieDocumento = new EspecieDocumento_Caixa(espDocCaixa.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); boleto.NumeroDocumento = "0000002"; boleto.DataProcessamento = DateTime.Now; boleto.DataDocumento = DateTime.Now; boletoBancario.Boleto = boleto; boletoBancario.MostrarComprovanteEntrega = true; boletoBancario.FormatoCarne = false; boletoBancario.Boleto.Valida(); Panel1.Controls.Add(boletoBancario); } else { BoletoBancario[] arrayDeBoletos = new BoletoBancario[quantidadeDeParcelas]; DateTime dataDeVencimento = new DateTime(2015, 09, 30); for (int j = 0; j < arrayDeBoletos.Length; j++) { BoletoBancario boletoBancario = new BoletoBancario(); boletoBancario.CodigoBanco = (short)104; DateTime dataDoDocumeto = new DateTime(2015, 09, 29); DateTime DataDoProcessamento = new DateTime(2015, 09, 29); Cedente c = new Cedente("17.405.814/0001-09", "Instituto Suporte Educacional Treinamento Especializado", "0773", "997", "9"); c.Codigo = "377306"; Boleto boleto = new Boleto(dataDeVencimento, 5.01m, "SR", "24000000000000002", c); boleto.DataDocumento = dataDoDocumeto; boleto.DataProcessamento = DataDoProcessamento; boleto.Sacado = new Sacado("111.111.111-11", "José"); boleto.Sacado.Endereco.End = "Rua Floriano Peixoto, S/N"; boleto.Sacado.Endereco.Bairro = "Centro"; boleto.Sacado.Endereco.Cidade = "Campina Grande"; boleto.Sacado.Endereco.CEP = "58100-000"; boleto.Sacado.Endereco.UF = "PB"; /* //Adiciona as instruções ao boleto #region Instruções Instrucao_Caixa item; //ImportanciaporDiaDesconto item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.Multa, Convert.ToDecimal(0.40)); boleto.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.JurosdeMora, Convert.ToDecimal(0.01)); boleto.Instrucoes.Add(item); item = new Instrucao_Caixa((int)EnumInstrucoes_Caixa.NaoReceberAposNDias, 90); boleto.Instrucoes.Add(item); #endregion Instruções */ EspecieDocumento_Caixa espDocCaixa = new EspecieDocumento_Caixa(); boleto.EspecieDocumento = new EspecieDocumento_Caixa(espDocCaixa.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); boleto.NumeroDocumento = "0000002"; boleto.DataProcessamento = DateTime.Now; boleto.DataDocumento = DateTime.Now; boletoBancario.Boleto = boleto; boletoBancario.MostrarComprovanteEntrega = true; boletoBancario.FormatoCarne = true; boletoBancario.Boleto.Valida(); arrayDeBoletos[j] = boletoBancario; dataDeVencimento = dataDeVencimento.AddMonths(1); } for (int k = 0; k < arrayDeBoletos.Length; k++) { Panel1.Controls.Add(arrayDeBoletos[k]); } } }
protected void btnGerarBoleto_ButtonClick(object sender, EventArgs e) { // Boleto para CEF, com carteira SR e nosso número de 11 dígitos. if (ExisteErroDePreenchimento()) { return; } try { var vencimento = txtVencimento.SelectedDate.Value.ToString("dd/MM/yyyy"); var valorBoleto = txtValor.Value.Value; IBoletosGeradosAux dadosAuxiliares = null; // Busca dados auxiliares no banco, se for a primeira vez, efetua o insert long cedenteNossoNumeroBoleto = 0; if (ViewState["CHAVE_CEDENTE_BOLETOGERADO"] != null) { // Numero do documento - numero de controle interno, não afeta o calculo da linha digitavel e nem o codigo de barras // mais pode ser útil, exemplo: quando o cliente ligar, vc pode consultar por este número e ver // se já foi efetuado o pagamento // cedente BoletoGerado = (IBoletosGerados)ViewState["CHAVE_CEDENTE_BOLETOGERADO"]; cedenteNossoNumeroBoleto = BoletoGerado.NossoNumero.Value; // o final do nosso número é incrementado ao final } else if (ViewState["CHAVE_LISTA_ITEM_FINANCEIRO"] != null) { var listaDeItensFinanceiros = (List<IItemLancamentoFinanceiroRecebimento>)ViewState["CHAVE_LISTA_ITEM_FINANCEIRO"]; if (listaDeItensFinanceiros.Count > 0) { foreach (var itemLancamentoFinanceiroRecebimento in listaDeItensFinanceiros) { long idboleto; using (var servicoFinanceiroComBoleto = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItemFinanceiroRecebidoComBoleto>()) idboleto = servicoFinanceiroComBoleto.ObtenhaBoletoPorIdItemFinanRecebimento( itemLancamentoFinanceiroRecebimento.ID.Value); if (idboleto > 0) { IBoletosGerados boletoGeradoParaItemFinanceiro; using (var servicoBoletoGeradoParaItemFinanceiro = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeBoleto>()) boletoGeradoParaItemFinanceiro = servicoBoletoGeradoParaItemFinanceiro.obtenhaBoletoPeloId( idboleto); if (boletoGeradoParaItemFinanceiro != null) cedenteNossoNumeroBoleto = boletoGeradoParaItemFinanceiro.NossoNumero.Value; } else { using (var servico = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeBoleto>()) dadosAuxiliares = servico.obtenhaProximasInformacoesParaGeracaoDoBoleto(ctrlCedente.CedenteSelecionado); cedenteNossoNumeroBoleto = dadosAuxiliares.ProximoNossoNumero.Value; } break; } } } else { using (var servico = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeBoleto>()) dadosAuxiliares = servico.obtenhaProximasInformacoesParaGeracaoDoBoleto(ctrlCedente.CedenteSelecionado); // Numero do documento - numero de controle interno, não afeta o calculo da linha digitavel e nem o codigo de barras // mais pode ser útil, exemplo: quando o cliente ligar, vc pode consultar por este número e ver // se já foi efetuado o pagamento // cedente cedenteNossoNumeroBoleto = dadosAuxiliares.ProximoNossoNumero.Value; // o final do nosso número é incrementado ao final } // obtendo a configuração do cedente var cedenteSelecionado = ctrlCedente.CedenteSelecionado; var cedenteCpfCnpj = string.Empty; var cedenteNome = string.Empty; var cedenteAgencia = string.Empty; var cedenteConta = string.Empty; var cedenteDigitoConta = string.Empty; var cedenteOperacaoConta = string.Empty; var cedenteCodigo = string.Empty; var imagemDoRecibo = string.Empty; var codigoDoBanco = 0; var carteira = string.Empty; if (cedenteSelecionado != null) { // pegar imagem do cedente para o boleto //imagemDoRecibo = configuracaoDoBoleto.ImagemDeCabecalhoDoReciboDoSacado; if (!string.IsNullOrEmpty(cedenteSelecionado.ImagemDeCabecalhoDoReciboDoSacado)) imagemDoRecibo = cedenteSelecionado.ImagemDeCabecalhoDoReciboDoSacado; var cedentePessoa = cedenteSelecionado.Pessoa; cedenteNome = cedentePessoa.Nome; codigoDoBanco = Convert.ToInt32(cedenteSelecionado.NumeroDoBanco); cedenteAgencia = cedenteSelecionado.NumeroDaAgencia; cedenteConta = cedenteSelecionado.NumeroDaConta; cedenteOperacaoConta = cedenteSelecionado.TipoDaConta.ToString("000"); if (!string.IsNullOrEmpty(cedenteConta)) cedenteDigitoConta = cedenteConta.Substring(cedenteConta.Length - 1, 1); //if (cedentePessoa.DadoBancario != null) //{ // codigoDoBanco = cedentePessoa.DadoBancario.Agencia.Banco.Numero; // cedenteAgencia = cedentePessoa.DadoBancario.Agencia.Numero; // cedenteConta = cedentePessoa.DadoBancario.Conta.Numero; // cedenteOperacaoConta = cedentePessoa.DadoBancario.Conta.Tipo.Value.ToString("000"); // if (!string.IsNullOrEmpty(cedenteConta)) // cedenteDigitoConta = cedenteConta.Substring(cedenteConta.Length - 1, 1); //} cedenteCpfCnpj = OtenhaNumeroCPFOuCNPJ(cedentePessoa); carteira = cedenteSelecionado.TipoDeCarteira.Sigla; } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), UtilidadesWeb.MostraMensagemDeInformacao("Configurações do cedente ou boleto bancário inválidas, favor verificar."), false); return; } // formata código do cedente if (!string.IsNullOrEmpty(cedenteOperacaoConta) && !string.IsNullOrEmpty(cedenteConta)) { string conta; var contaSemDigito = Convert.ToInt32(cedenteConta.Substring(0, cedenteConta.Length - 1)); conta = contaSemDigito.ToString("00000000"); cedenteCodigo = cedenteOperacaoConta + conta; } var cedente = new Cedente(cedenteCpfCnpj, cedenteNome, cedenteAgencia, cedenteConta, cedenteDigitoConta) { Codigo = cedenteCodigo }; var boleto = new Boleto(Convert.ToDateTime(vencimento), (decimal)valorBoleto, carteira, cedenteNossoNumeroBoleto.ToString(), cedente) { NumeroDocumento = txtNumeroDoBoleto.Text }; //sacado var sacadoCpfCnpj = txtCNPJCPF.Text; var sacadoNome = txtNome.Text; var sacadoEndereco = txtEndereco.Text; var sacadoObservacao = txtFinalidadeBoleto.Text; var sacado = new Sacado(sacadoCpfCnpj, sacadoNome); boleto.Sacado = sacado; boleto.Sacado.Endereco.End = sacadoEndereco; boleto.Sacado.Endereco.Bairro = txtBairro.Text; boleto.Sacado.Endereco.Cidade = txtCidade.Text; boleto.Sacado.Endereco.CEP = txtCep.Text; boleto.Sacado.Endereco.UF = txtEstado.Text; var instrucaoCaixa = new Instrucao_Caixa { Descricao = txtInstrucoes.Text }; instrucaoCaixa.DescricaoReciboDoSacado = sacadoObservacao; boleto.Instrucoes.Add(instrucaoCaixa); var especificacao = new EspecieDocumento_Caixa(); boleto.EspecieDocumento = new EspecieDocumento_Caixa(especificacao.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.Recibo)); boleto.DataProcessamento = DateTime.Now; boleto.DataDocumento = DateTime.Now; BoletoBancario boletoBancario; if (string.IsNullOrEmpty(imagemDoRecibo)) boletoBancario = new BoletoBancario(); else { var urlImagemLogo = UtilidadesWeb.ObtenhaURLHostDiretorioVirtual() + imagemDoRecibo.Remove(0, 1); boletoBancario = new BoletoBancario(urlImagemLogo); } boletoBancario.CodigoBanco = (short)codigoDoBanco; boletoBancario.Boleto = boleto; boletoBancario.MostrarCodigoCarteira = true; boletoBancario.Boleto.Valida(); boletoBancario.MostrarComprovanteEntrega = false; var chaveDoBoleto = Guid.NewGuid().ToString(); Session.Add(chaveDoBoleto, boletoBancario); MostraBoleto(boletoBancario); var url = String.Concat(UtilidadesWeb.ObtenhaURLHostDiretorioVirtual(), "FN/frmVisualizarBoletoGerado.aspx", "?Id=", chaveDoBoleto); ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), UtilidadesWeb.ExibeJanela(url, "Visualizar boleto gerado", 800, 600, "FN_frmVisualizarBoletoGerado_aspx"), false); // Salvar dados do Boleto gerado var boletoGerado = FabricaGenerica.GetInstancia().CrieObjeto<IBoletosGerados>(); boletoGerado.Cedente = ctrlCedente.CedenteSelecionado; boletoGerado.Cliente = ctrlCliente.ClienteSelecionado; boletoGerado.DataGeracao = boleto.DataProcessamento; boletoGerado.DataVencimento = txtVencimento.SelectedDate.Value; boletoGerado.NossoNumero = cedenteNossoNumeroBoleto; boletoGerado.NumeroBoleto = txtNumeroDoBoleto.Text; boletoGerado.Observacao = sacadoObservacao; boletoGerado.Valor = valorBoleto; boletoGerado.Instrucoes = txtInstrucoes.Text; using (var servico = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeBoleto>()) { if (BoletoGerado != null) { boletoGerado.ID = BoletoGerado.ID.Value; boletoGerado.StatusBoleto = BoletoGerado.StatusBoleto; servico.AtualizarBoletoGerado(boletoGerado); IItemLancamentoFinanceiroRecebimento itemLancamento; long idItemFinanceiroRecebido; using (var servicoDeItemFinanceiroRecebidoComBoleto = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItemFinanceiroRecebidoComBoleto>()) { idItemFinanceiroRecebido = servicoDeItemFinanceiroRecebidoComBoleto.ObtenhaItemFinanRecebimentoPorIdBoleto(boletoGerado.ID.Value); } if(idItemFinanceiroRecebido > 0) { using (var servicoFinanceiro = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItensFinanceirosDeRecebimento>()) { itemLancamento = servicoFinanceiro.Obtenha(idItemFinanceiroRecebido); if (itemLancamento != null) { itemLancamento.Cliente = boletoGerado.Cliente; if (boletoGerado.DataVencimento != null) itemLancamento.DataDoVencimento = boletoGerado.DataVencimento.Value; itemLancamento.Valor = boletoGerado.Valor; if (boletoGerado.NossoNumero != null) itemLancamento.NumeroBoletoGerado = boletoGerado.NossoNumero.Value.ToString(); itemLancamento.BoletoFoiGeradoColetivamente = false; servicoFinanceiro.Modifique(itemLancamento); } } } } else if (ViewState["CHAVE_LISTA_ITEM_FINANCEIRO"] != null) { var listaDeItensFinanceiros = (List<IItemLancamentoFinanceiroRecebimento>) ViewState["CHAVE_LISTA_ITEM_FINANCEIRO"]; if (listaDeItensFinanceiros.Count > 0) { // mais de 1 item financeiro selecionado if(listaDeItensFinanceiros.Count > 1) { long idBoletoExistente = 0; foreach (var itemLancamentoFinanceiroRecebimento in listaDeItensFinanceiros) { long idboleto = 0; using (var servicoFinanceiroComBoleto = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItemFinanceiroRecebidoComBoleto>()) { idboleto = servicoFinanceiroComBoleto.ObtenhaBoletoPorIdItemFinanRecebimento( itemLancamentoFinanceiroRecebimento.ID.Value); if (idboleto > 0) { idBoletoExistente = idboleto; //servico.Excluir(idboleto); }//servicoFinanceiroComBoleto.Excluir(itemLancamentoFinanceiroRecebimento.ID.Value); } break; //using (var servicoFinanceiro = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItensFinanceirosDeRecebimento>()) //{ // itemLancamentoFinanceiroRecebimento.Situacao = Situacao.Cancelada; // itemLancamentoFinanceiroRecebimento.Observacao = // "Item de contas a receber foi cancelado, para a geração de um novo item."; // servicoFinanceiro.Modifique(itemLancamentoFinanceiroRecebimento); //} } if (idBoletoExistente > 0) { // Este caso vai acontecer quando existe boleto gerado(mesmo boleto) para as contas a receber // ou seja, os dados do boleto vai atualizar using (var servicoBoletoGeradoParaItemFinanceiro = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeBoleto>()) { var boletoGeradoParaItemFinanceiro = servicoBoletoGeradoParaItemFinanceiro.obtenhaBoletoPeloId( idBoletoExistente); boletoGeradoParaItemFinanceiro.NumeroBoleto = boletoGerado.NumeroBoleto; boletoGeradoParaItemFinanceiro.Valor = boletoGerado.Valor; boletoGeradoParaItemFinanceiro.DataGeracao = boletoGerado.DataGeracao; boletoGeradoParaItemFinanceiro.DataVencimento = boletoGerado.DataVencimento; boletoGeradoParaItemFinanceiro.Observacao = boletoGerado.Observacao; boletoGeradoParaItemFinanceiro.Instrucoes = boletoGerado.Instrucoes; servico.AtualizarBoletoGerado(boletoGeradoParaItemFinanceiro); } } else { // Este caso vai acontecer quando existe mais de uma conta a receber, e está gerando um novo boleto, // ou seja, não existe boleto gerado para as contas boletoGerado.StatusBoleto = StatusBoleto.Status.Aberto.ToString(); boletoGerado.EhBoletoAvulso = false; servico.Inserir(boletoGerado, false, TipoLacamentoFinanceiroRecebimento.RecebimentoDeManutencao); // incrementar o nosso numero e o numero do documento e atualizar no banco. dadosAuxiliares.ProximoNossoNumero = dadosAuxiliares.ProximoNossoNumero + 1; servico.AtualizarProximasInformacoes(dadosAuxiliares); foreach (var itemLancamentoFinanceiroRecebimento in listaDeItensFinanceiros) { using (var servicoFinanceiro = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItensFinanceirosDeRecebimento>()) { itemLancamentoFinanceiroRecebimento.Situacao = Situacao.CobrancaGerada; itemLancamentoFinanceiroRecebimento.NumeroBoletoGerado = boletoGerado.NossoNumero.Value.ToString(); itemLancamentoFinanceiroRecebimento.BoletoFoiGeradoColetivamente = true; servicoFinanceiro.Modifique(itemLancamentoFinanceiroRecebimento); } using (var servicoFinanceiroComBoleto = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItemFinanceiroRecebidoComBoleto>()) { servicoFinanceiroComBoleto.Insira(itemLancamentoFinanceiroRecebimento.ID.Value, boletoGerado.ID.Value); } } } } else { foreach (var itemLancamentoFinanceiroRecebimento in listaDeItensFinanceiros) { long idboleto; using (var servicoFinanceiroComBoleto = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItemFinanceiroRecebidoComBoleto>()) { idboleto = servicoFinanceiroComBoleto.ObtenhaBoletoPorIdItemFinanRecebimento( itemLancamentoFinanceiroRecebimento.ID.Value); } if (idboleto > 0) { boletoGerado.ID = idboleto; servico.AtualizarBoletoGerado(boletoGerado); using (var servicoFinanceiro = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItensFinanceirosDeRecebimento>()) { itemLancamentoFinanceiroRecebimento.Cliente = boletoGerado.Cliente; if (boletoGerado.DataVencimento != null) itemLancamentoFinanceiroRecebimento.DataDoVencimento = boletoGerado.DataVencimento.Value; itemLancamentoFinanceiroRecebimento.Valor = boletoGerado.Valor; if (boletoGerado.NossoNumero != null) itemLancamentoFinanceiroRecebimento.NumeroBoletoGerado = boletoGerado.NossoNumero.Value.ToString(); itemLancamentoFinanceiroRecebimento.Situacao = Situacao.CobrancaGerada; itemLancamentoFinanceiroRecebimento.BoletoFoiGeradoColetivamente = false; servicoFinanceiro.Modifique(itemLancamentoFinanceiroRecebimento); } } else { boletoGerado.StatusBoleto = StatusBoleto.Status.Aberto.ToString(); boletoGerado.EhBoletoAvulso = false; servico.Inserir(boletoGerado, false, TipoLacamentoFinanceiroRecebimento.RecebimentoDeManutencao); // incrementar o nosso numero e o numero do documento e atualizar no banco. dadosAuxiliares.ProximoNossoNumero = dadosAuxiliares.ProximoNossoNumero + 1; servico.AtualizarProximasInformacoes(dadosAuxiliares); using (var servicoFinanceiro = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItensFinanceirosDeRecebimento>()) { itemLancamentoFinanceiroRecebimento.Cliente = boletoGerado.Cliente; if (boletoGerado.DataVencimento != null) itemLancamentoFinanceiroRecebimento.DataDoVencimento = boletoGerado.DataVencimento.Value; itemLancamentoFinanceiroRecebimento.Valor = boletoGerado.Valor; if (boletoGerado.NossoNumero != null) itemLancamentoFinanceiroRecebimento.NumeroBoletoGerado = boletoGerado.NossoNumero.Value.ToString(); itemLancamentoFinanceiroRecebimento.Situacao = Situacao.CobrancaGerada; itemLancamentoFinanceiroRecebimento.BoletoFoiGeradoColetivamente = false; servicoFinanceiro.Modifique(itemLancamentoFinanceiroRecebimento); } using (var servicoFinanceiroComBoleto = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeItemFinanceiroRecebidoComBoleto>()) { servicoFinanceiroComBoleto.Insira(itemLancamentoFinanceiroRecebimento.ID.Value, boletoGerado.ID.Value); } } } } } } else { boletoGerado.StatusBoleto = StatusBoleto.Status.Aberto.ToString(); boletoGerado.EhBoletoAvulso = true; servico.Inserir(boletoGerado, BoletoGeraItemFinanceiroDeRecebimento, TipoLacamentoFinanceiroRecebimento.BoletoAvulso); // incrementar o nosso numero e o numero do documento e atualizar no banco. dadosAuxiliares.ProximoNossoNumero = dadosAuxiliares.ProximoNossoNumero + 1; servico.AtualizarProximasInformacoes(dadosAuxiliares); } } } catch (BussinesException ex) { Logger.GetInstancia().Erro("Erro ao gerar boleto, exceção: ", ex); ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), UtilidadesWeb.MostraMensagemDeInconsitencia("Erro ao gerar boleto, exceção: " + ex.Message), false); } //Garante que a tela de contas a receber será atualizada. ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), UtilidadesWeb.AtualizaJanela(String.Concat(UtilidadesWeb.ObtenhaURLHostDiretorioVirtual(), "FN/frmContasAReceber.aspx"), "FN_frmContasAReceber_aspx"), false); //Garante que a tela de historico de boletos seja atualizada ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), UtilidadesWeb.AtualizaJanela(String.Concat(UtilidadesWeb.ObtenhaURLHostDiretorioVirtual(), "FN/frmBoletosGerados.aspx"), "FN_frmBoletosGerados_aspx"), false); }
protected void Page_Load(object sender, EventArgs e) { List<BoletoBancario> listaAuxiliar = new List<BoletoBancario>(); //Dados dos boletos short codigoDoBanco = 104; //Configura as datas do boleto DateTime dataDoDocumeto = DateTime.Now; String dataDoDocumentoString = dataDoDocumeto.ToString("dd/MM/YYYY"); DateTime dataDeVencimento = DateTime.Now.AddDays(5); String dataDoVencimentoString = dataDoDocumeto.ToString("dd-MM-YYYY"); DateTime dataDoProcessamento = DateTime.Now; String dataDoProcessamentoString = dataDoDocumeto.ToString("dd-MM-YYYY"); String cnpjDoCedente = "11.111.111/0001-10"; String nomeDoCedente = "Nome do Cedente"; String agenciaDoCedente = "1111"; String contaDoCedente = "1111"; String digitoDaConta = "4"; String codigoDoCedente = "123456"; decimal valorDoCarne = 5; String valorDoCarneString = Convert.ToString(valorDoCarne); String carteira = "SR"; String codigoDoBancoNossoNumero = "24"; String complementoNossoNumero = "000000000000001"; String nossoNumero = codigoDoBancoNossoNumero + complementoNossoNumero; String cpfDoSacado = "111.111.111-11"; String nomeDoSacado = "Nome do Sacado"; String ruaDoSacado = "Rua do sacado"; String bairroDoSacado = "Bairro do Sacado"; String cidadeDoSacado = "Cidade do Sacado"; String cepDoSacado = "58100-000"; String estadoDoSacado = "PB"; String numeroDocumento = "0000001"; int numeroDeParcelas = 2; String numeroDeParcelasString = Convert.ToString(numeroDeParcelas); //################################################### //################ - Cria boleto 1 - ################ //################################################### BoletoBancario boletoBancario = new BoletoBancario(); boletoBancario.CodigoBanco = codigoDoBanco; //Cria cedente Cedente c = new Cedente(cnpjDoCedente, nomeDoCedente, agenciaDoCedente, contaDoCedente, digitoDaConta); c.Codigo = codigoDoCedente; Boleto boleto = new Boleto(dataDeVencimento, valorDoCarne, carteira, nossoNumero, c); boleto.DataDocumento = dataDoDocumeto; boleto.DataProcessamento = dataDoProcessamento; boleto.Sacado = new Sacado(cpfDoSacado, nomeDoSacado); boleto.Sacado.Endereco.End = ruaDoSacado; boleto.Sacado.Endereco.Bairro = bairroDoSacado; boleto.Sacado.Endereco.Cidade = cidadeDoSacado; boleto.Sacado.Endereco.CEP = cepDoSacado; boleto.Sacado.Endereco.UF = estadoDoSacado; EspecieDocumento_Caixa espDocCaixa = new EspecieDocumento_Caixa(); boleto.EspecieDocumento = new EspecieDocumento_Caixa(espDocCaixa.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); boleto.NumeroDocumento = numeroDocumento; boleto.DataProcessamento = dataDoProcessamento; boleto.DataDocumento = dataDoDocumeto; boletoBancario.Boleto = boleto; boletoBancario.MostrarComprovanteEntrega = true; boletoBancario.FormatoCarne = true; boletoBancario.Boleto.Valida(); //################################################### //################ - Cria boleto 2 - ################ //################################################### BoletoBancario boletoBancario2 = new BoletoBancario(); boletoBancario2.CodigoBanco = codigoDoBanco; //Cria cedente Boleto boleto2 = new Boleto(dataDeVencimento, valorDoCarne, carteira, nossoNumero, c); boleto2.DataDocumento = dataDoDocumeto; boleto2.DataProcessamento = dataDoProcessamento; boleto2.Sacado = new Sacado(cpfDoSacado, nomeDoSacado); boleto2.Sacado.Endereco.End = ruaDoSacado; boleto2.Sacado.Endereco.Bairro = bairroDoSacado; boleto2.Sacado.Endereco.Cidade = cidadeDoSacado; boleto2.Sacado.Endereco.CEP = cepDoSacado; boleto2.Sacado.Endereco.UF = estadoDoSacado; boleto2.EspecieDocumento = new EspecieDocumento_Caixa(espDocCaixa.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); boleto2.NumeroDocumento = numeroDocumento; boleto2.DataProcessamento = dataDoProcessamento; boleto2.DataDocumento = dataDoDocumeto; boletoBancario2.Boleto = boleto2; boletoBancario2.MostrarComprovanteEntrega = true; boletoBancario2.FormatoCarne = true; boletoBancario2.Boleto.Valida(); //################################################### //################ - Cria boleto 3 - ################ //################################################### BoletoBancario boletoBancario3 = new BoletoBancario(); boletoBancario3.CodigoBanco = codigoDoBanco; //Cria cedente Boleto boleto3 = new Boleto(dataDeVencimento, valorDoCarne, carteira, nossoNumero, c); boleto3.DataDocumento = dataDoDocumeto; boleto3.DataProcessamento = dataDoProcessamento; boleto3.Sacado = new Sacado(cpfDoSacado, nomeDoSacado); boleto3.Sacado.Endereco.End = ruaDoSacado; boleto3.Sacado.Endereco.Bairro = bairroDoSacado; boleto3.Sacado.Endereco.Cidade = cidadeDoSacado; boleto3.Sacado.Endereco.CEP = cepDoSacado; boleto3.Sacado.Endereco.UF = estadoDoSacado; boleto3.EspecieDocumento = new EspecieDocumento_Caixa(espDocCaixa.getCodigoEspecieByEnum(EnumEspecieDocumento_Caixa.DuplicataMercantil)); boleto3.NumeroDocumento = numeroDocumento; boleto3.DataProcessamento = dataDoProcessamento; boleto3.DataDocumento = dataDoDocumeto; boletoBancario3.Boleto = boleto3; boletoBancario3.MostrarComprovanteEntrega = true; boletoBancario3.FormatoCarne = true; boletoBancario3.Boleto.Valida(); //################################################### //###### - Adiciona Boletos na ListaAuxiliar - ###### //################################################### listaAuxiliar.Add(boletoBancario); listaAuxiliar.Add(boletoBancario2); listaAuxiliar.Add(boletoBancario3); for (int i=0; i < listaAuxiliar.Count; i++) { Panel1.Controls.Add(listaAuxiliar[i]); } Label1.Text = listaAuxiliar.Count.ToString(); }