Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. @Autowired
  2. private RelatorioService relatorioService;
  3.  
  4. @GetMapping("/vendasEmitidas")
  5. public ModelAndView relatorioVendasEmitidas() {
  6. ModelAndView mv = new ModelAndView("relatorio/RelatorioVendasEmitidas");
  7. mv.addObject(new PeriodoRelatorio());
  8. return mv;
  9. }
  10.  
  11. @GetMapping("/controleEntregas")
  12. public ModelAndView relatorioControleEntrega() {
  13. ModelAndView mv = new ModelAndView("relatorio/RelatorioControleEntrega");
  14. mv.addObject(new ControleEntregaCodigo());
  15.  
  16. return mv;
  17. }
  18.  
  19. @PostMapping(value ="/controleEntregas", params = "emitir")
  20. public ResponseEntity<byte[]> gerarControleEntrega(ControleEntregaCodigo controleEntregaCodigo) throws Exception {
  21. byte[] relatorio = relatorioService.gerarControleEntrega(controleEntregaCodigo);
  22. return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF_VALUE)
  23. .body(relatorio);
  24. }
  25.  
  26. @GetMapping("/produtoPrecos")
  27. public ModelAndView relatorioProdutosPrecoVenda() {
  28. ModelAndView mv = new ModelAndView("relatorio/RelatorioProdutoPrecoVenda");
  29. mv.addObject(new PrecoRelatorio());
  30. return mv;
  31. }
  32.  
  33. @PostMapping("/vendasEmitidas")
  34. public ResponseEntity<byte[]> gerarRelatorioVendasEmitidas(PeriodoRelatorio periodoRelatorio) throws Exception {
  35. byte[] relatorio = relatorioService.gerarRelatorioVendasEmitidas(periodoRelatorio);
  36. return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF_VALUE)
  37. .body(relatorio);
  38. }
  39.  
  40.  
  41. @PostMapping("/controleEntregas")
  42. public ResponseEntity<byte[]> emitirControleEntrega(ControleEntregaCodigo controleEntregaCodigo) throws Exception {
  43. byte[] relatorio = relatorioService.gerarControleEntrega(controleEntregaCodigo);
  44. return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF_VALUE)
  45. .body(relatorio);
  46. }
  47.  
  48. @PostMapping("/produtoPrecos")
  49. public ResponseEntity<byte[]> gerarRelatorioProdutoPreco(PrecoRelatorio precoRelatorio) throws Exception {
  50. byte[] relatorio = relatorioService.gerarRelatorioProdutoPreco(precoRelatorio);
  51. return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF_VALUE)
  52. .body(relatorio);
  53. }
  54.  
  55. @Autowired
  56. private DataSource dataSource;
  57.  
  58. // relatórido de venda por periodo
  59. public byte[] gerarRelatorioVendasEmitidas(PeriodoRelatorio periodoRelatorio) throws Exception {
  60. Date dataInicio = Date.from(LocalDateTime.of(periodoRelatorio.getDataInicio(), LocalTime.of(0, 0, 0))
  61. .atZone(ZoneId.systemDefault()).toInstant());
  62. Date dataFim = Date.from(LocalDateTime.of(periodoRelatorio.getDataFim(), LocalTime.of(23, 59, 59))
  63. .atZone(ZoneId.systemDefault()).toInstant());
  64.  
  65. Map<String, Object> parametros = new HashMap<>();
  66. parametros.put("format", "pdf");
  67. parametros.put("data_inicio", dataInicio);
  68. parametros.put("data_fim", dataFim);
  69.  
  70. InputStream inputStream = this.getClass().getResourceAsStream("/relatorios/relatorio_vendas_emitidas.jasper");
  71.  
  72. Connection con = this.dataSource.getConnection();
  73.  
  74. try {
  75. JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parametros, con);
  76. return JasperExportManager.exportReportToPdf(jasperPrint);
  77. } finally {
  78. con.close();
  79. }
  80.  
  81. }
  82. // imprimir controle de entrega
  83.  
  84. public byte[] gerarControleEntrega(ControleEntregaCodigo controleEntregaCodigo) throws Exception {
  85.  
  86. Map<String, Object> parametros = new HashMap<>();
  87. parametros.put("format", "pdf");
  88. parametros.put("codigo", controleEntregaCodigo.getCodigo());
  89.  
  90. InputStream inputStream = this.getClass().getResourceAsStream("/relatorios/relatorio_controle_entrega.jasper");
  91.  
  92. Connection con = this.dataSource.getConnection();
  93.  
  94. try {
  95. JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parametros, con);
  96. return JasperExportManager.exportReportToPdf(jasperPrint);
  97. } finally {
  98. con.close();
  99. }
  100. }
  101.  
  102. // relatório de produtos por valor de venda
  103. public byte[] gerarRelatorioProdutoPreco(PrecoRelatorio precoRelatorio) throws Exception {
  104.  
  105. Map<String, Object> parametros = new HashMap<>();
  106. parametros.put("format", "pdf");
  107. parametros.put("valor_inicial", precoRelatorio.getValorInicial());
  108. parametros.put("valor_final", precoRelatorio.getValorFinal());
  109. // System.out.println(" valor inicial: " +
  110. // precoRelatorio.getValorInicial()+ "valor final:
  111. // "+precoRelatorio.getValorFinal() );
  112. InputStream inputStream = this.getClass().getResourceAsStream("/relatorios/relatorio_produto_valor.jasper");
  113.  
  114. Connection con = this.dataSource.getConnection();
  115.  
  116. try {
  117. JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parametros, con);
  118. return JasperExportManager.exportReportToPdf(jasperPrint);
  119. } finally {
  120. con.close();
  121. }
  122.  
  123. }
  124.  
  125. <a class="btn btn-link btn-xs js-tooltip " title="Imprimir"
  126. th:href="@{/relatorios/controleEntregas{codigo}(codigo=${venda.codigo})}"
  127. >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement