Advertisement
Guest User

Untitled

a guest
Oct 1st, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.53 KB | None | 0 0
  1. public ActionResult relatorioImpresso(string ini, string fim)
  2. {
  3. var cookie = DinheiroControlado.Repositorios.RepositoriosUsuarios.VerificaSeOUsuarioEstaLogado();
  4. if (cookie != null)
  5. {
  6.  
  7. //var teste = Request.Form["Buscar"];
  8.  
  9.  
  10. //-- Classificação, filtragem paginação
  11.  
  12. var hj = DateTime.Today;
  13. var dados = from d in db.Movimentacoes
  14. where d.IDUsuario == cookie.IDUsuario
  15. //orderby d.Data descending
  16. select d;
  17. var verificaOrcamento = from d in db.Orcamentos
  18. where d.IDUsuario == cookie.IDUsuario //&& hj.Month == d.MesBase.Month && hj.Year == d.MesBase.Year
  19. select d;
  20.  
  21. var totreceitas = from r in db.Movimentacoes
  22. where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "RECEITA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
  23. select r;
  24. var totdespesas = from r in db.Movimentacoes
  25. where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "DESPESA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
  26. select r;
  27. //-- Classificação, filtragem paginação
  28.  
  29. if (!String.IsNullOrEmpty(ini) && !String.IsNullOrEmpty(fim))
  30. {
  31. DateTime iniDate = Convert.ToDateTime(ini);
  32. DateTime fimDate = Convert.ToDateTime(fim);
  33. dados = dados.Where(s => s.Data >= iniDate && s.Data <= fimDate);
  34. verificaOrcamento = verificaOrcamento.Where(s => s.MesBase >= iniDate && s.MesBase <= fimDate);
  35. totreceitas = totreceitas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
  36. totdespesas = totdespesas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
  37. }
  38. else // && hj.Month == d.Data.Month && hj.Year == d.Data.Year
  39. {
  40. dados = dados.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
  41. verificaOrcamento = verificaOrcamento.Where(s => s.MesBase.Month == hj.Month && s.MesBase.Year == hj.Year);
  42. totreceitas = totreceitas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
  43. totdespesas = totdespesas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
  44. }
  45.  
  46.  
  47.  
  48. //-- Classificação, filtragem paginação
  49.  
  50. var totrec = totreceitas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
  51. var totdes = totdespesas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
  52. var orcamento = verificaOrcamento.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
  53.  
  54.  
  55. ViewBag.receitas = totrec;
  56. ViewBag.despesas = totdes;
  57. if (dados.Count() == 0)
  58. {
  59. ViewBag.Saldo = 0;
  60. }
  61. else
  62. {
  63.  
  64. ViewBag.Saldo = totrec - totdes;
  65. }
  66.  
  67.  
  68.  
  69. return View(dados);
  70. }
  71. else
  72. {
  73. return RedirectToRoute("Index", "Login");
  74. }
  75. }
  76.  
  77. public ActionResult PDFPadrao(string ini, string fim)
  78. {
  79. var cookie = DinheiroControlado.Repositorios.RepositoriosUsuarios.VerificaSeOUsuarioEstaLogado();
  80. ViewBag.Usuario = cookie.Nome;
  81. if (cookie != null)
  82. {
  83.  
  84. //var dataini = Request.Form.
  85. //var datafim = Request.Form["fim"];
  86.  
  87.  
  88. //-- Classificação, filtragem paginação
  89.  
  90. var hj = DateTime.Today;
  91. var dados = from d in db.Movimentacoes
  92. where d.IDUsuario == cookie.IDUsuario
  93. //orderby d.Data descending
  94. select d;
  95. var verificaOrcamento = from d in db.Orcamentos
  96. where d.IDUsuario == cookie.IDUsuario //&& hj.Month == d.MesBase.Month && hj.Year == d.MesBase.Year
  97. select d;
  98.  
  99. var totreceitas = from r in db.Movimentacoes
  100. where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "RECEITA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
  101. select r;
  102. var totdespesas = from r in db.Movimentacoes
  103. where r.IDUsuario == cookie.IDUsuario && r.ReceitaDespesa == "DESPESA" //&& hj.Month == r.Data.Month && hj.Year == r.Data.Year
  104. select r;
  105. //-- Classificação, filtragem paginação
  106.  
  107. if (!String.IsNullOrEmpty(ini) && !String.IsNullOrEmpty(fim))
  108. {
  109. DateTime iniDate = Convert.ToDateTime(ini);
  110. DateTime fimDate = Convert.ToDateTime(fim);
  111. dados = dados.Where(s => s.Data >= iniDate && s.Data <= fimDate);
  112. verificaOrcamento = verificaOrcamento.Where(s => s.MesBase >= iniDate && s.MesBase <= fimDate);
  113. totreceitas = totreceitas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
  114. totdespesas = totdespesas.Where(s => s.Data >= iniDate && s.Data <= fimDate);
  115. }
  116. else // && hj.Month == d.Data.Month && hj.Year == d.Data.Year
  117. {
  118. dados = dados.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
  119. verificaOrcamento = verificaOrcamento.Where(s => s.MesBase.Month == hj.Month && s.MesBase.Year == hj.Year);
  120. totreceitas = totreceitas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
  121. totdespesas = totdespesas.Where(s => s.Data.Month == hj.Month && s.Data.Year == hj.Year);
  122. }
  123.  
  124.  
  125.  
  126. //-- Classificação, filtragem paginação
  127.  
  128. var totrec = totreceitas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
  129. var totdes = totdespesas.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
  130. var orcamento = verificaOrcamento.AsQueryable().Sum(x => (decimal?)x.Valor) ?? 0;
  131.  
  132.  
  133. ViewBag.receitas = totrec;
  134. ViewBag.despesas = totdes;
  135. if (dados.Count() == 0)
  136. {
  137. ViewBag.Saldo = 0;
  138. }
  139. else
  140. {
  141.  
  142. ViewBag.Saldo = totrec - totdes;
  143. }
  144. /* decimal perc2 = 0;
  145.  
  146. if (orcamento > 0)
  147. {
  148. var perc = orcamento - totdes;
  149. perc = perc / orcamento;
  150. perc = perc * 100;
  151. perc2 = 100 - perc;
  152. ViewBag.Orcamento = perc2;
  153. }
  154. else if (orcamento == 0)
  155. {
  156. ViewBag.Orcamento = orcamento;
  157. }*/
  158.  
  159. //perc2.ToString("00.00");
  160. /*if (orcamento == 0)
  161. {
  162. ViewBag.Orcamento = "Orçamento não cadastrado";
  163. }
  164. else if (totdes <= orcamento)
  165. {
  166. ViewBag.Orcamento = "Dentro do Orçamento: " + perc2.ToString("00.00") + "% do Orçamento Comprometido";
  167. }
  168. else
  169. {
  170. ViewBag.Orcamento = "Fora do Orçamento: " + perc2.ToString("00.00") + "% do Orçamento Comprometido";
  171. }
  172. if (dados.Count() == 0)
  173. {
  174. ViewBag.Saldo = 0;
  175. }
  176. else
  177. {
  178.  
  179. ViewBag.Saldo = totrec - totdes;
  180. }*/
  181.  
  182. ViewAsPdf pdf = new ViewAsPdf();
  183. pdf.IsGrayScale = true;
  184. pdf.Model = dados;
  185. pdf.PageMargins = new Rotativa.Options.Margins(10, 10, 10, 10);
  186. pdf.ViewName = "PDFPadrao";
  187. return pdf;
  188. }
  189. else
  190. {
  191. return RedirectToRoute("Index", "Login");
  192. }
  193. }
  194.  
  195. @model IEnumerable<DinheiroControlado.Models.Movimentacoes>
  196.  
  197. @{
  198. ViewBag.Title = "RelatorioImpresso";
  199. Layout = "~/Views/Layout2.cshtml";
  200. }
  201. <section id="title" class="emerald">
  202. <div class="container">
  203. <div class="row">
  204. <div class="col-sm-6">
  205. <h1>Relátórios</h1>
  206. <p>Analise suas contas linha a linha e imprima caso necessário!</p>
  207. </div>
  208. <div class="col-sm-6">
  209. <ul class="breadcrumb pull-right">
  210. <li><a href="@Url.Action("Index","Home")">Home</a></li>
  211. <li class="active">Relatórios</li>
  212. </ul>
  213. </div>
  214. </div>
  215. </div>
  216. </section>
  217.  
  218. <section>
  219. @using (Html.BeginForm())
  220. {
  221. <section>
  222. <div class="container">
  223. <table>
  224. <tr>
  225. <th>
  226. @Html.TextBox("ini", null, new { @class = "form-control", @placeholder = "Data Inicial", @id = "datepicker", @size = "10"})
  227. </th>
  228. <th>
  229. @Html.TextBox("fim", null, new { @class = "form-control", @placeholder = "Data Final", @id = "datepicker2", @size = "10"})
  230. </th>
  231. <th>
  232. <input type="submit" value="Buscar" class="btn btn-primary"/>
  233. </th>
  234. <th>
  235. <a href="@Url.Action("PDFPadrao", "Relatorio")" target="_blank" class="btn btn-primary">Imprimir PDF</a>
  236. </th>
  237. </tr>
  238. </table>
  239. </div>
  240. </section>
  241. }
  242.  
  243. </section>
  244. <section>
  245. <div class="container">
  246. <table class= "table table-striped" >
  247. <tr>
  248. <th>
  249. @Html.DisplayNameFor(model => model.Data)
  250.  
  251. </th>
  252. <th>
  253. @Html.DisplayNameFor(model => model.Descricao)
  254. </th>
  255. <th>
  256. @Html.DisplayNameFor(model => model.ReceitaDespesa)
  257. </th>
  258. <th>
  259. @Html.DisplayNameFor(model => model.Valor)
  260. </th>
  261. <th>
  262. @Html.DisplayNameFor(model => model.Categorias.Categoria)
  263. </th>
  264.  
  265. </tr>
  266.  
  267. @foreach (var item in Model) {
  268. <tr>
  269. <td>
  270. @Html.DisplayFor(modelItem => item.Data)
  271. </td>
  272. <td>
  273. @Html.DisplayFor(modelItem => item.Descricao)
  274. </td>
  275. <td>
  276. @Html.DisplayFor(modelItem => item.ReceitaDespesa)
  277. </td>
  278. <td>
  279. @Html.DisplayFor(modelItem => item.Valor)
  280. </td>
  281. <td>
  282. @Html.DisplayFor(modelItem => item.Categorias.Categoria)
  283. </td>
  284.  
  285. </tr>
  286. }
  287.  
  288. </table>
  289. </div>
  290. </section>
  291. <section>
  292. <div class="container">
  293. <table class="table">
  294. <tr>
  295. <th>
  296. <p>Total Despesas</p>
  297. </th>
  298. <th>
  299. <p><font color = "ff0000">@ViewBag.despesas.ToString("C2") </font></p>
  300. </th>
  301. <th>
  302. <p>Total Receitas</p>
  303. </th>
  304. <th>
  305. <p><font color = "0000ff">@ViewBag.receitas.ToString("C2")</font></p>
  306. </th>
  307. <th>
  308. <p>Saldo Autal</p>
  309. </th>
  310. <th>
  311. @{
  312. var i2 = ViewBag.Saldo;
  313. if (i2 < 0)
  314. {
  315. <p><font color = "ff0000">@ViewBag.Saldo.ToString("C2")</font></p>
  316. } else {
  317. <p><font color = "0000ff">@ViewBag.Saldo.ToString("C2")</font></p>
  318. }
  319. }
  320. </th>
  321. </tr>
  322. </table>
  323. </div>
  324. </section>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement