private List <ResumoCategoriaMesModel> gerarListaDespesa(string sMesAno) { List <ResumoCategoriaMesModel> retorno = new List <ResumoCategoriaMesModel>(); DateTime dDataInicio = new DateTime(int.Parse(sMesAno.Substring(2, 4)), int.Parse(sMesAno.Substring(0, 2)), 1); DateTime dDataFim = dDataInicio.AddMonths(1) - (new TimeSpan(0, 0, 0, 1)); // tudo do mês sem cartão de crédito List <ExpenseIncome> lstMesAtual = expenseIncomeBusiness.Get.Where(e => e.sUserID == AuthProvider.UserAntenticated.sID && e.dData >= dDataInicio && e.dData <= dDataFim && e.CategoryType == CategoryType.Despesa).OrderBy(e => e.sCategoryID).ToList(); foreach (ExpenseIncome exp in lstMesAtual) { Account conta = accountBusiness.Get.FirstOrDefault(c => c.sID == exp.sAccountID); if (conta.AccountType != AccountType.CartaoDeCredito) { ResumoCategoriaMesModel resumo = new ResumoCategoriaMesModel(); resumo.dData = exp.dData; resumo.dValor = exp.dValor; resumo.sCategoryID = exp.sCategoryID; resumo.sDescCategoria = categoryBusiness.Get.FirstOrDefault(c => c.sID == exp.sCategoryID).descricao; resumo.sDescConta = accountBusiness.Get.FirstOrDefault(a => a.sID == exp.sAccountID).sNome; resumo.sDescricao = exp.sDescricao; if (exp.iTotalOcorrencia > 1) { resumo.sDescricao += " - " + exp.iNumeroOcorrencia + "/" + exp.iTotalOcorrencia; } retorno.Add(resumo); } } // tudo do mês pago por cartão de crédito lstMesAtual = expenseIncomeBusiness.Get.Where(e => e.sUserID == AuthProvider.UserAntenticated.sID && e.dData >= dDataInicio && e.dData <= dDataFim && e.CategoryType == CategoryType.PagamentoCartaoCredito).OrderBy(e => e.sCategoryID).ToList(); foreach (ExpenseIncome exp in lstMesAtual) { List <ExpenseIncomeReference> lstCartao = expenseIncomeReferenceBusiness.Get.Where(e => e.sExpenseIncomeDestinyID == exp.sID).ToList(); foreach (ExpenseIncomeReference expRef in lstCartao) { ExpenseIncome expPago = expenseIncomeBusiness.Get.FirstOrDefault(e => e.sID == expRef.sExpenseIncomeOriginID); if (expPago.CategoryType == CategoryType.Despesa) { ResumoCategoriaMesModel resumo = new ResumoCategoriaMesModel(); resumo.dData = expPago.dData; resumo.dValor = expPago.dValor; resumo.sCategoryID = expPago.sCategoryID; resumo.sDescCategoria = categoryBusiness.Get.FirstOrDefault(c => c.sID == expPago.sCategoryID).descricao; resumo.sDescConta = accountBusiness.Get.FirstOrDefault(a => a.sID == expPago.sAccountID).sNome; resumo.sDescricao = expPago.sDescricao; if (expPago.iTotalOcorrencia > 1) { resumo.sDescricao += " - " + expPago.iNumeroOcorrencia + "/" + expPago.iTotalOcorrencia; } retorno.Add(resumo); } } } return(retorno); }
private PagedList.IPagedList <ResumoCategoriaMesModel> gerarListaResumoCategoria(int pagina, string sMesAnoCategoriaID) { string sMesAno = sMesAnoCategoriaID.Substring(0, 6); string sCategoriaID = sMesAnoCategoriaID.Substring(6); List <ResumoCategoriaMesModel> lstResumo = new List <ResumoCategoriaMesModel>(); Category category = categoryBusiness.Get.FirstOrDefault(c => c.sID == sCategoriaID); if (string.IsNullOrEmpty(sMesAno)) { sMesAno = DateTime.Today.ToString("MMyyyy"); } DateTime dDataInicio = new DateTime(Int32.Parse(sMesAno.Substring(2, 4)), Int32.Parse(sMesAno.Substring(0, 2)), 1); DateTime dDataFim = dDataInicio.AddMonths(1) - (new TimeSpan(0, 0, 0, 1)); List <ExpenseIncome> lstMesAtual = expenseIncomeBusiness.Get.Where(e => e.sUserID == AuthProvider.UserAntenticated.sID && e.dData >= dDataInicio && e.dData <= dDataFim && e.sCategoryID == sCategoriaID && e.iNumeroOcorrencia == 1).OrderBy(e => e.dData).ThenBy(e => e.sDescricao).ToList(); foreach (ExpenseIncome exp in lstMesAtual) { ResumoCategoriaMesModel rcm = new ResumoCategoriaMesModel(); rcm.dData = exp.dData; rcm.dValor = exp.dValor; rcm.sDescricao = exp.sDescricao; rcm.sAgrupadorID = exp.sAgrupadorOcorrencia; if (exp.iTotalOcorrencia > 1) { rcm.sDescricao += " (" + exp.iTotalOcorrencia + "x)"; } rcm.sDescConta = accountBusiness.Get.FirstOrDefault(a => a.sID == exp.sAccountID).sNome; lstResumo.Add(rcm); } foreach (ResumoCategoriaMesModel rcm in lstResumo) { if (!string.IsNullOrEmpty(rcm.sAgrupadorID)) { lstMesAtual = expenseIncomeBusiness.Get.Where(e => e.sAgrupadorOcorrencia == rcm.sAgrupadorID).ToList(); double dTotal = 0; foreach (ExpenseIncome expInc in lstMesAtual) { dTotal += expInc.dValor; } rcm.dValor = dTotal; } } return(lstResumo.ToPagedList(pagina, 17)); }