private void setValoresClienteMesGasto(ClientesGastoMesReport clientesGasto, IList <Ordem> ordensAno) { foreach (var mes in clientesGasto.ClienteMes) { mes.Clientes = ordensAno .GroupBy(r => new { r.DataAtendimento.Month, r.Cliente }) .Where(r => r.Key.Month == mes.NumMes) .Select(cl => new ClienteGasto { Mes = DateTimeFormatInfo.CurrentInfo.GetMonthName(cl.Key.Month), Nome = cl.Key.Cliente.Nome, ValorTotal = cl.Sum(c => c.Valor) }).OrderByDescending(r => r.ValorTotal).Take(3).ToList(); } }
private void populaMesAnoClienteGasto(ClientesGastoMesReport clientesGasto, string[] meses) { int count = 1; foreach (var mes in meses) { if (!string.IsNullOrEmpty(mes)) { clientesGasto.ClienteMes.Add(new MesesAno() { Nome = mes, NumMes = count }); count++; } } }
public ClientesGastoMesReport getGastoMes() { try { var ordensAno = orderRepo.findByYear(); string[] meses = DateTimeFormatInfo.CurrentInfo.MonthNames; ClientesGastoMesReport clientesGasto = new ClientesGastoMesReport(); clientesGasto.ClienteMes = new List <MesesAno>(); populaMesAnoClienteGasto(clientesGasto, meses); setValoresClienteMesGasto(clientesGasto, ordensAno); return(clientesGasto); } catch (Exception ex) { throw ex; } }