Example #1
0
        public ActionResult EmitirReportEmprestimos(EmprestimoSearchModel searchModel)
        {
            var query = EmprestimosModel.GetBaseQuery(db, searchModel).OrderByDescending(q => q.DtEmprestimo);

            var model = new EmprestimoSearchViewModel
            {
                SearchModel = searchModel,
                Termo = searchModel.Search,
                FoundObjects = query.Count(),
                Objetos = (from objeto in query.ToList()
                           let pessoa = objeto.Pessoa
                           let livros = objeto.ItensEmprestimo.ToList()
                           let dtDevolucao = (objeto.Status == (int)Enumerations.Emprestimo.StatusEmprestimo.Devolvido ? objeto.ItensEmprestimo.Select(s => s.DtDevolucao).FirstOrDefault() : (DateTime?)null)
                           select new EmprestimoViewModel
                           {
                               Id = objeto.Id,
                               PessoaId = pessoa.Id,
                               PessoaText = pessoa.Nome,
                               LivrosText = string.Join("; ", livros.Select(x => x.Livro.Titulo).ToList()),
                               StatusId = (int)objeto.Status,
                               StatusText = EnumsHelper.GetText(typeof(Enumerations.Emprestimo.StatusEmprestimo), (int)objeto.Status),
                               DtEmprestimo = objeto.DtEmprestimo,
                               DtEmprestimoText = objeto.DtEmprestimo.ToShortDateString(),
                               DtPrevisaoDevolucao = objeto.DtPrevisaoDevolucao,
                               DtPrevisaoDevolucaoText = objeto.DtPrevisaoDevolucao.HasValue ? objeto.DtPrevisaoDevolucao.Value.ToShortDateString() : string.Empty,
                               DtDevolucao = dtDevolucao,
                               DtDevolucaoText = dtDevolucao.HasValue ? dtDevolucao.Value.ToShortDateString() : string.Empty,
                               DtCadastro = objeto.DtHrCadastro,
                               DtCadastroText = objeto.DtHrCadastro.ToShortDateString(),
                           }).OrderByDescending(ob => ob.DtEmprestimo).ToList()
            };

            ViewBag.Title = string.Format("Relatório de {0}", "Empréstimos");
            ViewBag.Subtitle = string.Format(Constantes.GeradoEm_, Genericos.GetDateTimeFromBrazil());

            return new ViewAsPdf("EmprestimoSearchResultList", model)
            {
                FileName = "RelatorioEmprestimos.pdf",
                PageSize = Size.A4,
                PageOrientation = Orientation.Landscape,
                PageMargins = { Top = 1, Left = 1, Right = 1, Bottom = 1 }
            };
        }
Example #2
0
        public static IQueryable<Emprestimo> GetBaseQuery(SBSCEntities db, EmprestimoSearchModel searchModel)
        {
            IQueryable<Emprestimo> query = db.Emprestimo;

            if (!string.IsNullOrEmpty(searchModel.Search))
            {
                var term = searchModel.Search.Trim();

                query = from q in query
                        where term.Contains(q.Id.ToString())
                            // Itens do emprestimo
                            || q.ItensEmprestimo.Any(ie => ie.Livro.Titulo.Contains(term))
                            || q.ItensEmprestimo.Any(ie => ie.Livro.Genero.Contains(term))
                            || q.ItensEmprestimo.Any(ie => ie.Livro.Autor.Contains(term))
                            || q.ItensEmprestimo.Any(ie => ie.Livro.Editora.Contains(term))
                            || q.ItensEmprestimo.Any(ie => ie.Livro.Local.Contains(term))
                            // Pessoa
                            || q.Pessoa.Nome.Contains(term)
                            || q.Pessoa.Login.Contains(term)
                        select q;
            }

            return query;
        }
Example #3
0
        private List<WidgetListaViewModel> GetWidgetNumerosEmprestimos()
        {
            var searchModel = new EmprestimoSearchModel();

            var emprestimos = EmprestimosModel.GetBaseQuery(db, searchModel);

            var currentYear = Genericos.GetDateTimeFromBrazil().Year;
            var lastYear = currentYear - 1;

            var lista = new List<WidgetListaViewModel>();

            lista.Add(new WidgetListaViewModel()
            {
                Description = "Total de empréstimos",
                Total = emprestimos.Count()
            });

            lista.Add(new WidgetListaViewModel()
            {
                Description = "Empréstimos em aberto (sem atraso)",
                Total = emprestimos.Count(c => c.Status == (int)Enumerations.Emprestimo.StatusEmprestimo.Emprestado)
            });

            lista.Add(new WidgetListaViewModel()
            {
                Description = "Empréstimos em aberto (com atraso)",
                Total = emprestimos.Count(c => c.Status == (int)Enumerations.Emprestimo.StatusEmprestimo.Emprestado)
            });

            lista.Add(new WidgetListaViewModel()
            {
                Description = "Empréstimos realizados",
                Total = emprestimos.Count(c => c.Status == (int)Enumerations.Emprestimo.StatusEmprestimo.Devolvido)
            });

            lista.Add(new WidgetListaViewModel()
            {
                Description = string.Format("Empréstimos realizados este ano ({0})", currentYear),
                Total = emprestimos.Count(c => c.Status == (int)Enumerations.Emprestimo.StatusEmprestimo.Devolvido
                    && c.DtEmprestimo.Year == currentYear)
            });

            lista.Add(new WidgetListaViewModel()
            {
                Description = string.Format("Empréstimos realizados ano passado ({0})", lastYear),
                Total = emprestimos.Count(c => c.Status == (int)Enumerations.Emprestimo.StatusEmprestimo.Devolvido
                    && c.DtEmprestimo.Year == lastYear)
            });

            //lista.Add(new WidgetListaViewModel()
            //{
            //    Description = "Devoluções em atraso",
            //    Total = 0
            //});

            return lista;
        }