Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult relatorioImpresso(string ini, string fim)
- {
- var cookie = DinheiroControlado.Repositorios.RepositoriosUsuarios.VerificaSeOUsuarioEstaLogado();
- if (cookie != null)
- {
- //var teste = Request.Form["Buscar"];
- //-- Classificação, filtragem paginação
- var hj = DateTime.Today;
- var dados = from d in db.Movimentacoes
- where d.IDUsuario == cookie.IDUsuario
- //orderby d.Data descending
- select d;
- var verificaOrcamento = from d in db.Orcamentos
- where d.IDUsuario == cookie.IDUsuario //&& hj.Month == d.MesBase.Month && hj.Year == d.MesBase.Year
- select d;
- var totreceitas = from r in db.Movimentacoes
- where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "RECEITA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
- select r;
- var totdespesas = from r in db.Movimentacoes
- where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "DESPESA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
- select r;
- //-- Classificação, filtragem paginação
- if (!String.IsNullOrEmpty(ini) && !String.IsNullOrEmpty(fim))
- {
- DateTime iniDate = Convert.ToDateTime(ini);
- DateTime fimDate = Convert.ToDateTime(fim);
- dados = dados.Where(s => s.Data >= iniDate && s.Data <= fimDate);
- verificaOrcamento = verificaOrcamento.Where(s => s.MesBase >= iniDate && s.MesBase <= fimDate);
- totreceitas = totreceitas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
- totdespesas = totdespesas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
- }
- else // && hj.Month == d.Data.Month && hj.Year == d.Data.Year
- {
- dados = dados.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
- verificaOrcamento = verificaOrcamento.Where(s => s.MesBase.Month == hj.Month && s.MesBase.Year == hj.Year);
- totreceitas = totreceitas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
- totdespesas = totdespesas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
- }
- //-- Classificação, filtragem paginação
- var totrec = totreceitas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
- var totdes = totdespesas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
- var orcamento = verificaOrcamento.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
- ViewBag.receitas = totrec;
- ViewBag.despesas = totdes;
- if (dados.Count() == 0)
- {
- ViewBag.Saldo = 0;
- }
- else
- {
- ViewBag.Saldo = totrec - totdes;
- }
- return View(dados);
- }
- else
- {
- return RedirectToRoute("Index", "Login");
- }
- }
- public ActionResult PDFPadrao(string ini, string fim)
- {
- var cookie = DinheiroControlado.Repositorios.RepositoriosUsuarios.VerificaSeOUsuarioEstaLogado();
- ViewBag.Usuario = cookie.Nome;
- if (cookie != null)
- {
- //var dataini = Request.Form.
- //var datafim = Request.Form["fim"];
- //-- Classificação, filtragem paginação
- var hj = DateTime.Today;
- var dados = from d in db.Movimentacoes
- where d.IDUsuario == cookie.IDUsuario
- //orderby d.Data descending
- select d;
- var verificaOrcamento = from d in db.Orcamentos
- where d.IDUsuario == cookie.IDUsuario //&& hj.Month == d.MesBase.Month && hj.Year == d.MesBase.Year
- select d;
- var totreceitas = from r in db.Movimentacoes
- where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "RECEITA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
- select r;
- var totdespesas = from r in db.Movimentacoes
- where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "DESPESA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
- select r;
- //-- Classificação, filtragem paginação
- if (!String.IsNullOrEmpty(ini) && !String.IsNullOrEmpty(fim))
- {
- DateTime iniDate = Convert.ToDateTime(ini);
- DateTime fimDate = Convert.ToDateTime(fim);
- dados = dados.Where(s => s.Data >= iniDate && s.Data <= fimDate);
- verificaOrcamento = verificaOrcamento.Where(s => s.MesBase >= iniDate && s.MesBase <= fimDate);
- totreceitas = totreceitas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
- totdespesas = totdespesas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
- }
- else // && hj.Month == d.Data.Month && hj.Year == d.Data.Year
- {
- dados = dados.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
- verificaOrcamento = verificaOrcamento.Where(s => s.MesBase.Month == hj.Month && s.MesBase.Year == hj.Year);
- totreceitas = totreceitas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
- totdespesas = totdespesas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
- }
- //-- Classificação, filtragem paginação
- var totrec = totreceitas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
- var totdes = totdespesas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
- var orcamento = verificaOrcamento.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
- ViewBag.receitas = totrec;
- ViewBag.despesas = totdes;
- if (dados.Count() == 0)
- {
- ViewBag.Saldo = 0;
- }
- else
- {
- ViewBag.Saldo = totrec - totdes;
- }
- /* decimal perc2 = 0;
- if (orcamento > 0)
- {
- var perc = orcamento - totdes;
- perc = perc / orcamento;
- perc = perc * 100;
- perc2 = 100 - perc;
- ViewBag.Orcamento = perc2;
- }
- else if (orcamento == 0)
- {
- ViewBag.Orcamento = orcamento;
- }*/
- //perc2.ToString("00.00");
- /*if (orcamento == 0)
- {
- ViewBag.Orcamento = "Orçamento não cadastrado";
- }
- else if (totdes <= orcamento)
- {
- ViewBag.Orcamento = "Dentro do Orçamento: " + perc2.ToString("00.00") + "% do Orçamento Comprometido";
- }
- else
- {
- ViewBag.Orcamento = "Fora do Orçamento: " + perc2.ToString("00.00") + "% do Orçamento Comprometido";
- }
- if (dados.Count() == 0)
- {
- ViewBag.Saldo = 0;
- }
- else
- {
- ViewBag.Saldo = totrec - totdes;
- }*/
- ViewAsPdf pdf = new ViewAsPdf();
- pdf.IsGrayScale = true;
- pdf.Model = dados;
- pdf.PageMargins = new Rotativa.Options.Margins(10, 10, 10, 10);
- pdf.ViewName = "PDFPadrao";
- return pdf;
- }
- else
- {
- return RedirectToRoute("Index", "Login");
- }
- }
- @model IEnumerable<DinheiroControlado.Models.Movimentacoes>
- @{
- ViewBag.Title = "RelatorioImpresso";
- Layout = "~/Views/Layout2.cshtml";
- }
- <section id="title" class="emerald">
- <div class="container">
- <div class="row">
- <div class="col-sm-6">
- <h1>Relátórios</h1>
- <p>Analise suas contas linha a linha e imprima caso necessário!</p>
- </div>
- <div class="col-sm-6">
- <ul class="breadcrumb pull-right">
- <li><a href="@Url.Action("Index","Home")">Home</a></li>
- <li class="active">Relatórios</li>
- </ul>
- </div>
- </div>
- </div>
- </section>
- <section>
- @using (Html.BeginForm())
- {
- <section>
- <div class="container">
- <table>
- <tr>
- <th>
- @Html.TextBox("ini", null, new { @class = "form-control", @placeholder = "Data Inicial", @id = "datepicker", @size = "10"})
- </th>
- <th>
- @Html.TextBox("fim", null, new { @class = "form-control", @placeholder = "Data Final", @id = "datepicker2", @size = "10"})
- </th>
- <th>
- <input type="submit" value="Buscar" class="btn btn-primary"/>
- </th>
- <th>
- <a href="@Url.Action("PDFPadrao", "Relatorio")" target="_blank" class="btn btn-primary">Imprimir PDF</a>
- </th>
- </tr>
- </table>
- </div>
- </section>
- }
- </section>
- <section>
- <div class="container">
- <table class= "table table-striped" >
- <tr>
- <th>
- @Html.DisplayNameFor(model => model.Data)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.Descricao)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.ReceitaDespesa)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.Valor)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.Categorias.Categoria)
- </th>
- </tr>
- @foreach (var item in Model) {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.Data)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.Descricao)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.ReceitaDespesa)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.Valor)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.Categorias.Categoria)
- </td>
- </tr>
- }
- </table>
- </div>
- </section>
- <section>
- <div class="container">
- <table class="table">
- <tr>
- <th>
- <p>Total Despesas</p>
- </th>
- <th>
- <p><font color = "ff0000">@ViewBag.despesas.ToString("C2") </font></p>
- </th>
- <th>
- <p>Total Receitas</p>
- </th>
- <th>
- <p><font color = "0000ff">@ViewBag.receitas.ToString("C2")</font></p>
- </th>
- <th>
- <p>Saldo Autal</p>
- </th>
- <th>
- @{
- var i2 = ViewBag.Saldo;
- if (i2 < 0)
- {
- <p><font color = "ff0000">@ViewBag.Saldo.ToString("C2")</font></p>
- } else {
- <p><font color = "0000ff">@ViewBag.Saldo.ToString("C2")</font></p>
- }
- }
- </th>
- </tr>
- </table>
- </div>
- </section>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement