Commit baef5a8e20c6d9aeef89a26724481f037694b736
1 parent
5f83665c
Exists in
master
Redmine #4444 Refatoração para realizar o fechamento de mês em uma única transação.
Showing
3 changed files
with
190 additions
and
0 deletions
Show diff stats
citgrp-patrimonio-api/src/main/resources/scripts-bd/postgres/v1.13.0/01-cit-patrimonio-v1.13.0-postgres.sql
0 → 100644
... | ... | @@ -0,0 +1,9 @@ |
1 | +-- Geovane 12/04/2016 | |
2 | +-- Alterando fechamento do mês para patrimonio apenas | |
3 | +UPDATE menufile | |
4 | + SET caminho = '/citgrp-patrimonio-web/assets/js/angular/custom/repository/OrganizacaoPatrimonioRepository.js' | |
5 | + WHERE caminho = '/cit-adm-materiais-web/assets/js/angular/custom/repository/OrganizacaoAdmMateriaisRepository.js'; | |
6 | + | |
7 | +UPDATE menufile | |
8 | + SET caminho = '/citgrp-patrimonio-web/assets/js/angular/custom/repository/OrganizacaoPatrimonioRepository.min.js' | |
9 | + WHERE caminho = '/cit-adm-materiais-web/assets/js/angular/custom/repository/OrganizacaoAdmMateriaisRepository.min.js'; | |
0 | 10 | \ No newline at end of file | ... | ... |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/OrganizacaoPatrimonioController.java
0 → 100644
... | ... | @@ -0,0 +1,158 @@ |
1 | +package br.com.centralit.controller; | |
2 | + | |
3 | +import java.util.Calendar; | |
4 | +import java.util.Map; | |
5 | + | |
6 | +import javax.servlet.http.HttpServletRequest; | |
7 | + | |
8 | +import org.springframework.beans.factory.annotation.Autowired; | |
9 | +import org.springframework.security.core.context.SecurityContextHolder; | |
10 | +import org.springframework.stereotype.Controller; | |
11 | +import org.springframework.web.bind.annotation.RequestBody; | |
12 | +import org.springframework.web.bind.annotation.RequestMapping; | |
13 | +import org.springframework.web.bind.annotation.RequestMethod; | |
14 | +import org.springframework.web.bind.annotation.ResponseBody; | |
15 | + | |
16 | +import br.com.centralit.api.model.Depreciacao; | |
17 | +import br.com.centralit.api.model.MyMensagemRetorno; | |
18 | +import br.com.centralit.api.model.MyRetornoStatus; | |
19 | +import br.com.centralit.api.service.BemPatrimonialService; | |
20 | +import br.com.centralit.api.service.ContaContabilSaldoService; | |
21 | +import br.com.centralit.api.service.DepreciacaoService; | |
22 | +import br.com.centralit.api.service.DominioService; | |
23 | +import br.com.centralit.api.service.ModuloService; | |
24 | +import br.com.centralit.api.service.OrganizacaoService; | |
25 | +import br.com.centralit.framework.json.ResponseBodyWrapper; | |
26 | +import br.com.centralit.framework.json.Views; | |
27 | +import br.com.centralit.framework.model.Dominio; | |
28 | +import br.com.centralit.framework.model.Organizacao; | |
29 | +import br.com.centralit.framework.model.Usuario; | |
30 | + | |
31 | +/** | |
32 | + * | |
33 | + * <p><img src="http://centralit.com.br/images/logo_central.png"></p> | |
34 | + * | |
35 | + * <p><b>Company: </b> Central IT - Governança Corporativa - </p> | |
36 | + * | |
37 | + * <p><b>Title: </b></p> | |
38 | + * | |
39 | + * <p><b>Description: </b></p> | |
40 | + * | |
41 | + * <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p> | |
42 | + * | |
43 | + * <p><b>Regra(s) de negócio:</b> <a href="LINK_PORTAL">NUMERO_REGRA_DE_NEGOCIO</a></p> | |
44 | + * | |
45 | + * @since 12/04/2016 - 09:23:49 | |
46 | + * | |
47 | + * @version 1.0.0 | |
48 | + * | |
49 | + * @author geovane.filho | |
50 | + * | |
51 | + */ | |
52 | +@Controller | |
53 | +@RequestMapping("/rest/organizacaoPatrimonio") | |
54 | +public class OrganizacaoPatrimonioController { | |
55 | + | |
56 | + /** Atributo organizacaoService. */ | |
57 | + @Autowired | |
58 | + private OrganizacaoService organizacaoService; | |
59 | + | |
60 | + /** Atributo contaContabilSaldoService. */ | |
61 | + @Autowired | |
62 | + private ContaContabilSaldoService contaContabilSaldoService; | |
63 | + | |
64 | + /** Atributo bemPatrimonialService. */ | |
65 | + @Autowired | |
66 | + private BemPatrimonialService bemPatrimonialService; | |
67 | + | |
68 | + /** Atributo depreciacaoService. */ | |
69 | + @Autowired | |
70 | + private DepreciacaoService depreciacaoService; | |
71 | + | |
72 | + /** Atributo dominioService. */ | |
73 | + @Autowired | |
74 | + private DominioService dominioService; | |
75 | + | |
76 | + /** Atributo moduloService. */ | |
77 | + @Autowired | |
78 | + private ModuloService moduloService; | |
79 | + | |
80 | + /** Atributo request. */ | |
81 | + @Autowired | |
82 | + private HttpServletRequest request; | |
83 | + | |
84 | + /** | |
85 | + * | |
86 | + * <p> | |
87 | + * <b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a> | |
88 | + * </p> | |
89 | + * | |
90 | + * <p> | |
91 | + * <b>Regra(s) de negócio:</b> <a href="LINK_PORTAL">NUMERO_REGRA_DE_NEGOCIO</a> | |
92 | + * </p> | |
93 | + * | |
94 | + * Método responsável por realizar o fechamento do mes de referencia da Organizacao O fechamento do mês de referência contempla também a depreciação dos bens patrimoniais, o fechamento dos saldos das contas contabeis e a atualização do novo mês de referencia. | |
95 | + * | |
96 | + * @author geovane.filho | |
97 | + * | |
98 | + * @param request | |
99 | + * Pedido de fechamento do mes contendo a organização e o tipo de depreciação a ser realizado | |
100 | + * @return <code>ResponseBodyWrapper</code> contendo a atualização da organização após o fechamento | |
101 | + */ | |
102 | + @RequestMapping(value = "/fecharMes", method = RequestMethod.POST) | |
103 | + @ResponseBody | |
104 | + public ResponseBodyWrapper fecharMes(@RequestBody Map<String, Long> requisicaoFechamento) { | |
105 | + Usuario user = (Usuario) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | |
106 | + Organizacao organizacao = this.organizacaoService.find(requisicaoFechamento.get("organizacao")); | |
107 | + Long tipoDepreciacaoCodigo = requisicaoFechamento.get("tipoDepreciacao"); | |
108 | + | |
109 | + MyRetornoStatus retornoFechamentoBens = new MyRetornoStatus(); | |
110 | + | |
111 | + MyRetornoStatus retornoBensNaEstruturaAlmoxarifado = new MyRetornoStatus(); | |
112 | + | |
113 | + retornoBensNaEstruturaAlmoxarifado.status = this.bemPatrimonialService.validarBensNaEstruturaAlmoxarifado(organizacao.getId()); | |
114 | + retornoBensNaEstruturaAlmoxarifado.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.error, "MSG.BENS_NA_ESTRUTURA_ALMOXARIFADO")); | |
115 | + | |
116 | + if(!retornoBensNaEstruturaAlmoxarifado.status) { | |
117 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retornoBensNaEstruturaAlmoxarifado, Views.EstruturaOrganizacionalEditView.class); | |
118 | + return responseBody; | |
119 | + } | |
120 | + | |
121 | + retornoFechamentoBens.status = this.bemPatrimonialService.fecharValoresBens(organizacao.getId(), user.getId()); | |
122 | + | |
123 | + MyRetornoStatus retornoFechamentoContas = new MyRetornoStatus(); | |
124 | + retornoFechamentoContas.status = this.contaContabilSaldoService.fechaSaldoContasContabeisTipoPermanente(organizacao); | |
125 | + | |
126 | + if (retornoFechamentoBens.status && retornoFechamentoContas.status) { | |
127 | + MyRetornoStatus retornoDepreciacao = new MyRetornoStatus(); | |
128 | + | |
129 | + Dominio tipoDepreciacao = this.dominioService.findByChaveAndCodigo(Dominio.TIPO_DEPRECIACAO, tipoDepreciacaoCodigo); | |
130 | + | |
131 | + Depreciacao depreciacao = this.depreciacaoService.geraDepreciacao(organizacao, tipoDepreciacao, user.getId()); | |
132 | + | |
133 | + if (depreciacao != null) { | |
134 | + retornoDepreciacao = new MyRetornoStatus(depreciacao); | |
135 | + } else { | |
136 | + if (tipoDepreciacao == null) { | |
137 | + MyMensagemRetorno mensagem = new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.error, "MSG.FECHAR_MES_REFERENCIA_SEM_DEPRECIACAO"); | |
138 | + retornoDepreciacao.mensagens.add(mensagem); | |
139 | + } | |
140 | + } | |
141 | + | |
142 | + if (retornoDepreciacao.status) { // Se a depreciação foi realizada com sucesso eu atualizo o mês de referencia | |
143 | + retornoFechamentoContas.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.success, "MSG.SUCESSO_DEPRECIACAO")); | |
144 | + organizacao.getDataReferenciaVigente().add(Calendar.MONTH, 1); | |
145 | + this.organizacaoService.merge(organizacao); | |
146 | + retornoFechamentoContas.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.success, "MSG.SUCESSO_MES_REFERENCIA")); | |
147 | + } else { | |
148 | + retornoFechamentoContas.status = retornoDepreciacao.status; | |
149 | + retornoFechamentoContas.mensagens.addAll(retornoDepreciacao.mensagens); | |
150 | + } | |
151 | + } | |
152 | + | |
153 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retornoFechamentoContas, Views.EstruturaOrganizacionalEditView.class); | |
154 | + | |
155 | + return responseBody; | |
156 | + } | |
157 | + | |
158 | +} | |
0 | 159 | \ No newline at end of file | ... | ... |
citgrp-patrimonio-web/src/main/webapp/assets/js/angular/custom/repository/OrganizacaoPatrimonioRepository.js
0 → 100644
... | ... | @@ -0,0 +1,23 @@ |
1 | +'use strict'; | |
2 | + | |
3 | +citApp.factory('OrganizacaoPatrimonioRepository', ['RestangularPatrimonio', 'AbstractRepository', function (restangularPatrimonio, AbstractRepository) { | |
4 | + | |
5 | + function OrganizacaoPatrimonioRepository() { | |
6 | + AbstractRepository.call(this, restangularPatrimonio, 'rest/organizacaoPatrimonio'); | |
7 | + | |
8 | + //Método para realizar o fechamento do mês de um orgão passando o tipo de depreciação a ser realizada | |
9 | + this.fecharMes = function(organizacaoId, tipoDepreciacaoId) { | |
10 | + var request = { | |
11 | + organizacao : organizacaoId, | |
12 | + tipoDepreciacao : tipoDepreciacaoId | |
13 | + }; | |
14 | + | |
15 | + return restangularPatrimonio.all(this.route + '/fecharMes').post(request); | |
16 | + }; | |
17 | + | |
18 | + } | |
19 | + | |
20 | + AbstractRepository.extend(OrganizacaoPatrimonioRepository); | |
21 | + | |
22 | + return new OrganizacaoPatrimonioRepository(); | |
23 | +}]); | ... | ... |