0
I have a query for a report, where some search fields are optional, except the date ranges.
However, when performing the query, the function always returns me values that do not match the parameters I passed at the time of execution of query
public List<IQueryable> ObterNotaDetalhada(DateTime compInicial, DateTime compFinal, PorteContribuinte? codigoPorte, string query, int? itemServico, bool? simplesNacional)
{
var res = this.Servicos
.Where(a => ((a.Competencia >= compInicial && a.Competencia <= compFinal) ||
(a.Prestador.Porte.Value == codigoPorte) || (a.Prestador.IsSimplesNacional == simplesNacional) ||
(a.ItemListaServico.Id == itemServico) ||
(a.Prestador.RazaoSocial.Contains(query) ||
a.Prestador.CpfCnpj.Contains(query))))
.OrderByDescending(a => (a.id))
.GroupBy(a => a.Prestador.CpfCnpj)
.Select(g => new
{
CNPJ = g.Key,
RazaoSocial = g.Select(x => x.Prestador.RazaoSocial),
SimplesNacional = g.Select(x => x.Prestador.IsSimplesNacional),
Porte = g.Select(x => x.Prestador.Porte),
QtdNotasEmitidas = g.Count(),
BaseDeCalculo = g.Select(x => x.BaseCalculo),
ValorDeducoes = g.Select(x => x.ValorDeducoes),
ValorServicos = g.Select(x => x.ValorServicos),
ValorIss = g.Select(x => x.ValorInss),
TotalBaseDeCalculo = g.Sum(x => x.BaseCalculo),
TotalValorDeducoes = g.Sum(x => x.ValorDeducoes),
TotalValorServicos = g.Sum(x => x.ValorServicos),
TotalValorIss = g.Sum(x => x.ValorIss),
IssRetido = g.Select(x => x.IssRetido > decimal.Zero),
ItemDeServico = g.Select(x => x.ItemListaServico.Descricao),
CodItemServico = g.Select(x=>x.ItemListaServico.Codigo)
});
return new List<IQueryable> { res };
}
The sending parameter for the method:
Note: When I search only with the date ranges, returns everything correctly.
An example of the search result:
Actually the error is in the logic you are using. If the national simple is NO or has size, it returns. This means that if the size is 3, it will return even if simple national is YES
– Raul Medeiros