public IEnumerable <Assinaturas.Models.Pagamento> ListarPagamento(int clienteID, int assinaturaTipoID, string filtro) { try { string sql = string.Format(@"SELECT DISTINCT b.Valor, b.TimeStamp, f.Nome as FormaPagamento , b.DataPagamento , p.FormaPagamentoID, b.DataVencimento , b.DataConfirmacao FROM tAssinaturaCliente ac(NOLOCK) INNER JOIN tAssinatura a (NOLOCK) ON a.ID = ac.AssinaturaID INNER JOIN tVendaBilheteria v(NOLOCK) ON ac.VendaBilheteriaID = v.ID INNER JOIN tVendaBilheteriaFormaPagamento p(NOLOCK) ON p.VendaBilheteriaID = v.ID INNER JOIN tVendaBilheteriaFormaPagamentoBoleto b(NOLOCK)ON b.VendaBilheteriaFormaPagamentoID = p.ID INNER JOIN tFormaPagamento f(NOLOCK) ON p.FormaPagamentoID = f.ID WHERE v.ClienteID = {0} {1} AND a.AssinaturaTipoID = {2} and (ac.status <> 'D' and ac.acao <> 'D') ", clienteID, filtro, assinaturaTipoID); bd.Consulta(sql); var lista = new List <Assinaturas.Models.Pagamento>(); FormaPagamento.ESTADO auxEstado = new FormaPagamento.ESTADO(); if (bd.Consulta().Read()) { do { auxEstado = FormaPagamento.ESTADO.Aberto; if (bd.LerDateTime("DataVencimento").Date < DateTime.Now.Date) { auxEstado = FormaPagamento.ESTADO.Vencido; } if (bd.LerDateTime("DataPagamento") > DateTime.MinValue) { auxEstado = FormaPagamento.ESTADO.Pago; } lista.Add(new Assinaturas.Models.Pagamento() { EstadoPagamento = auxEstado.ToString(), EstadoPagamentoID = Convert.ToInt32(auxEstado), Valor = bd.LerDecimal("Valor"), TimeStamp = bd.LerDateTime("TimeStamp"), FormaPagamento = bd.LerString("FormaPagamento"), DataPagamento = bd.LerDateTime("DataPagamento"), FormaPagamentoID = bd.LerInt("FormaPagamentoID"), DataVencimento = bd.LerDateTime("DataVencimento"), DataConfirmacao = bd.LerDateTime("DataConfirmacao"), }); } while (bd.Consulta().Read()); } bd.FecharConsulta(); string sql2 = string.Format(@"SELECT DISTINCT p.Valor, v.DataVenda as TimeStamp, f.Nome as FormaPagamento , v.DataVenda as DataPagamento , p.FormaPagamentoID FROM tAssinaturaCliente ac(NOLOCK) INNER JOIN tAssinatura a (NOLOCK) ON a.ID = ac.AssinaturaID INNER JOIN tVendaBilheteria v(NOLOCK) ON ac.VendaBilheteriaID = v.ID INNER JOIN tVendaBilheteriaFormaPagamento p(NOLOCK) ON p.VendaBilheteriaID = v.ID INNER JOIN tFormaPagamento f(NOLOCK) ON p.FormaPagamentoID = f.ID WHERE f.Tipo <> 3 AND v.ClienteID = {0} {1} and (ac.status <> 'D' and ac.acao <> 'D') AND a.AssinaturaTipoID = {2} ", clienteID, filtro, assinaturaTipoID); bd.Consulta(sql2); if (bd.Consulta().Read()) { do { lista.Add(new Assinaturas.Models.Pagamento() { EstadoPagamento = FormaPagamento.ESTADO.Pago.ToString(), EstadoPagamentoID = Convert.ToInt32(FormaPagamento.ESTADO.Pago), Valor = bd.LerDecimal("Valor"), TimeStamp = bd.LerDateTime("TimeStamp"), FormaPagamento = bd.LerString("FormaPagamento"), DataPagamento = bd.LerDateTime("DataPagamento"), FormaPagamentoID = bd.LerInt("FormaPagamentoID"), }); } while (bd.Consulta().Read()); } bd.FecharConsulta(); return(lista); } finally { bd.Fechar(); } }
public List <EstruturaBoleto> ListarBoleto(int clienteID, FormaPagamento.ESTADO?estadoBoleto, string senhaVenda, int codigoBoleto, int AssinaturaID, int AssinaturaTipoID, string AssinaturaAno) { try { string filtro = " ass.AssinaturaTipoID = " + AssinaturaTipoID + " AND Ano = " + AssinaturaAno; filtro += AssinaturaID > 0 ? " AND ass.ID = " + AssinaturaID : ""; filtro += clienteID > 0 ? " AND ac.ClienteID = " + clienteID : ""; filtro += senhaVenda != null && senhaVenda.Length > 0 ? " AND v.Senha = '" + senhaVenda + "' " : ""; filtro += codigoBoleto > 0 ? " AND b.ID = " + codigoBoleto : ""; string sql = string.Format(@"SELECT DISTINCT b.ID, b.Valor, b.Impresso, b.ValorPago, b.TimeStamp as DataEmissao, b.DataPagamento, b.DataVencimento, b.DataConfirmacao, c.CPF , c.Nome as Assinante, c.ID AS ClienteID, v.Senha as SenhaVenda, ass.Nome as AssinaturaNome FROM tVendaBilheteria v(nolock) INNER JOIN tVendaBilheteriaFormaPagamento p(NOLOCK) ON p.VendaBilheteriaID = v.ID INNER JOIN tVendaBilheteriaFormaPagamentoBoleto b(NOLOCK)ON b.VendaBilheteriaFormaPagamentoID = p.ID INNER JOIN tAssinaturaCliente ac(NOLOCK) ON ac.VendaBilheteriaID = v.ID INNER JOIN tAssinatura ass (NOLOCK) ON ass.ID = ac.AssinaturaID INNER JOIN tAssinaturaAno aa (NOLOCK) ON aa.AssinaturaID = ass.ID INNER JOIN tCliente c (NOLOCK) ON c.ID = ac.ClienteID WHERE {0}", filtro); bd.Consulta(sql); if (!bd.Consulta().Read()) { return(null); } var lista = new List <EstruturaBoleto>(); FormaPagamento.ESTADO auxEstado = new FormaPagamento.ESTADO(); do { auxEstado = FormaPagamento.ESTADO.Aberto; if (bd.LerDateTime("DataVencimento").Date < DateTime.Now.Date) { auxEstado = FormaPagamento.ESTADO.Vencido; } if (bd.LerDateTime("DataPagamento") > DateTime.MinValue) { auxEstado = FormaPagamento.ESTADO.Pago; } lista.Add(new EstruturaBoleto() { ID = bd.LerInt("ID"), Valor = bd.LerDecimal("Valor"), Impresso = bd.LerBoolean("Impresso"), ValorPago = bd.LerDecimal("ValorPago"), DataEmissao = bd.LerDateTime("DataEmissao"), DataPagamento = bd.LerDateTime("DataPagamento"), DataVencimento = bd.LerDateTime("DataVencimento"), DataConfirmacao = bd.LerDateTime("DataConfirmacao"), CPF = bd.LerString("CPF"), Assinante = bd.LerString("Assinante"), ClienteID = bd.LerInt("ClienteID"), SenhaVenda = bd.LerString("SenhaVenda"), AssinaturaNome = bd.LerString("AssinaturaNome"), Cancelado = false, EstadoPagamento = auxEstado, }); } while (bd.Consulta().Read()); bd.FecharConsulta(); string sql2 = string.Format(@"SELECT DISTINCT b.ID, b.Valor, b.Impresso, b.ValorPago, b.TimeStamp as DataEmissao, b.DataPagamento, b.DataVencimento, b.DataConfirmacao, c.CPF , c.Nome as Assinante, c.ID AS ClienteID, v.Senha as SenhaVenda, ass.Nome as AssinaturaNome FROM tVendaBilheteria v(nolock) INNER JOIN tVendaBilheteriaFormaPagamento p(NOLOCK) ON p.VendaBilheteriaID = v.ID INNER JOIN tVendaBilheteriaFormaPagamentoBoletoHistorico b(NOLOCK)ON b.VendaBilheteriaFormaPagamentoID = p.ID INNER JOIN tAssinaturaCliente ac(NOLOCK) ON ac.VendaBilheteriaID = v.ID INNER JOIN tAssinatura ass (NOLOCK) ON ass.ID = ac.AssinaturaID INNER JOIN tAssinaturaAno aa (NOLOCK) ON aa.AssinaturaID = ass.ID INNER JOIN tCliente c (NOLOCK) ON c.ID = ac.ClienteID WHERE {0}", filtro); bd.Consulta(sql2); if (bd.Consulta().Read()) { do { auxEstado = FormaPagamento.ESTADO.Aberto; if (bd.LerDateTime("DataVencimento").Date < DateTime.Now.Date) { auxEstado = FormaPagamento.ESTADO.Vencido; } if (bd.LerDateTime("DataPagamento") > DateTime.MinValue) { auxEstado = FormaPagamento.ESTADO.Pago; } lista.Add(new EstruturaBoleto() { ID = bd.LerInt("ID"), Valor = bd.LerDecimal("Valor"), Impresso = bd.LerBoolean("Impresso"), ValorPago = bd.LerDecimal("ValorPago"), DataEmissao = bd.LerDateTime("DataEmissao"), DataPagamento = bd.LerDateTime("DataPagamento"), DataVencimento = bd.LerDateTime("DataVencimento"), DataConfirmacao = bd.LerDateTime("DataConfirmacao"), CPF = bd.LerString("CPF"), Assinante = bd.LerString("Assinante"), ClienteID = bd.LerInt("ClienteID"), SenhaVenda = bd.LerString("SenhaVenda"), AssinaturaNome = bd.LerString("AssinaturaNome"), Cancelado = true, EstadoPagamento = auxEstado, }); } while (bd.Consulta().Read()); } bd.FecharConsulta(); if (estadoBoleto != null) { return(lista.Where(c => c.EstadoPagamento == estadoBoleto).ToList()); } return(lista); } finally { bd.Fechar(); } }