Commit 2affe85378aff1fb0d4e893435e45c52ea2eb2f9
1 parent
5fa0a340
Exists in
master
Redmine #4444 Refatoração para realizar o fechamento de mês em uma única transação.
Showing
8 changed files
with
92 additions
and
101 deletions
Show diff stats
cit-adm-materiais-api/src/main/java/br/com/centralit/api/dao/ContaContabilDao.java
... | ... | @@ -8,6 +8,7 @@ import java.util.Set; |
8 | 8 | |
9 | 9 | import br.com.centralit.api.model.ContaContabil; |
10 | 10 | import br.com.centralit.framework.dao.arquitetura.CitGenericDAO; |
11 | +import br.com.centralit.framework.model.Dominio; | |
11 | 12 | import br.com.centralit.framework.model.Organizacao; |
12 | 13 | |
13 | 14 | /** |
... | ... | @@ -262,4 +263,19 @@ public interface ContaContabilDao extends CitGenericDAO { |
262 | 263 | * @return |
263 | 264 | */ |
264 | 265 | ContaContabil findByMaterial(Long materialId); |
266 | + | |
267 | + /** | |
268 | + * <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p> | |
269 | + * | |
270 | + * <p><b>Regra(s) de negócio:</b> <a href="LINK_PORTAL">NUMERO_REGRA_DE_NEGOCIO</a></p> | |
271 | + * | |
272 | + * Método responsável por encontrar todas as contas contábeis de um determinado tipo de material para um orgão | |
273 | + * | |
274 | + * @author geovane.filho | |
275 | + * | |
276 | + * @param organizacao | |
277 | + * @param tipoMaterial | |
278 | + * @return | |
279 | + */ | |
280 | + Collection<ContaContabil> findAllByOrganizacaoAndTipoMaterial(Organizacao organizacao, Dominio tipoMaterial); | |
265 | 281 | } | ... | ... |
cit-adm-materiais-api/src/main/java/br/com/centralit/api/dao/impl/ContaContabilDaoHibernate.java
... | ... | @@ -14,6 +14,7 @@ import br.com.centralit.api.dao.ContaContabilDao; |
14 | 14 | import br.com.centralit.api.model.ContaContabil; |
15 | 15 | import br.com.centralit.framework.dao.arquitetura.CitGenericDAOImpl; |
16 | 16 | import br.com.centralit.framework.dao.arquitetura.SearchSeven; |
17 | +import br.com.centralit.framework.model.Dominio; | |
17 | 18 | import br.com.centralit.framework.model.Organizacao; |
18 | 19 | import br.com.centralit.framework.util.UtilColecao; |
19 | 20 | import br.com.centralit.framework.util.UtilObjeto; |
... | ... | @@ -468,4 +469,17 @@ public class ContaContabilDaoHibernate extends CitGenericDAOImpl implements Cont |
468 | 469 | resultado.setMaxResults(1); |
469 | 470 | return (ContaContabil) resultado.getSingleResult(); |
470 | 471 | } |
472 | + | |
473 | + /** | |
474 | + * {@inheritDoc} | |
475 | + */ | |
476 | + @Override | |
477 | + public Collection<ContaContabil> findAllByOrganizacaoAndTipoMaterial(Organizacao organizacao, Dominio tipoMaterial) { | |
478 | + Search search = new Search(); | |
479 | + | |
480 | + search.addFilterEqual("organizacao.id", organizacao.getId()); | |
481 | + search.addFilterEqual("dominioTipoMaterial.id", tipoMaterial.getId()); | |
482 | + | |
483 | + return this.search(search, ContaContabil.class); | |
484 | + } | |
471 | 485 | } | ... | ... |
cit-adm-materiais-api/src/main/java/br/com/centralit/api/service/ContaContabilSaldoService.java
... | ... | @@ -87,4 +87,18 @@ public interface ContaContabilSaldoService extends GenericService<ContaContabilS |
87 | 87 | * @return <code>true</code> caso exista saldo fechado para alguma conta deste orgão na data de referência passada, <code>false</code> caso contrário. |
88 | 88 | */ |
89 | 89 | Boolean existeSaldoOrganizacaoEDataReferencia(Organizacao organizacao, Calendar dataReferencia); |
90 | + | |
91 | + /** | |
92 | + * <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p> | |
93 | + * | |
94 | + * <p><b>Regra(s) de negócio:</b> <a href="LINK_PORTAL">NUMERO_REGRA_DE_NEGOCIO</a></p> | |
95 | + * | |
96 | + * Método responsável por fechar o saldo das contas contábeis de materiais do tipo permanente (Patrimônio) de um orgão. | |
97 | + * | |
98 | + * @author geovane.filho | |
99 | + * | |
100 | + * @param organizacao | |
101 | + * @return | |
102 | + */ | |
103 | + boolean fechaSaldoContasContabeisTipoPermanente(Organizacao organizacao); | |
90 | 104 | } | ... | ... |
cit-adm-materiais-api/src/main/java/br/com/centralit/api/service/ContaContabilService.java
... | ... | @@ -5,6 +5,7 @@ import java.util.Collection; |
5 | 5 | import java.util.List; |
6 | 6 | |
7 | 7 | import br.com.centralit.api.model.ContaContabil; |
8 | +import br.com.centralit.framework.model.Dominio; | |
8 | 9 | import br.com.centralit.framework.model.Organizacao; |
9 | 10 | import br.com.centralit.framework.service.arquitetura.GenericService; |
10 | 11 | |
... | ... | @@ -260,4 +261,19 @@ public interface ContaContabilService extends GenericService<ContaContabil, Long |
260 | 261 | */ |
261 | 262 | ContaContabil findByMaterial(Long materialId); |
262 | 263 | |
264 | + /** | |
265 | + * <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p> | |
266 | + * | |
267 | + * <p><b>Regra(s) de negócio:</b> <a href="LINK_PORTAL">NUMERO_REGRA_DE_NEGOCIO</a></p> | |
268 | + * | |
269 | + * Método responsável por encontrar todas as contas contabeis de um determinado tipo de material de um orgão. | |
270 | + * | |
271 | + * @author geovane.filho | |
272 | + * | |
273 | + * @param organizacao | |
274 | + * @param tipoMaterial | |
275 | + * @return | |
276 | + */ | |
277 | + Collection<ContaContabil> findAllByOrganizacaoAndTipoMaterial(Organizacao organizacao, Dominio tipoMaterial); | |
278 | + | |
263 | 279 | } | ... | ... |
cit-adm-materiais-api/src/main/java/br/com/centralit/api/service/impl/ContaContabilSaldoServiceImpl.java
... | ... | @@ -14,6 +14,8 @@ import br.com.centralit.api.model.ContaContabilSaldo; |
14 | 14 | import br.com.centralit.api.service.ContaContabilMovimentoService; |
15 | 15 | import br.com.centralit.api.service.ContaContabilSaldoService; |
16 | 16 | import br.com.centralit.api.service.ContaContabilService; |
17 | +import br.com.centralit.api.service.DominioService; | |
18 | +import br.com.centralit.framework.model.Dominio; | |
17 | 19 | import br.com.centralit.framework.model.Organizacao; |
18 | 20 | import br.com.centralit.framework.service.arquitetura.GenericServiceImpl; |
19 | 21 | import br.com.centralit.framework.util.UtilDate; |
... | ... | @@ -49,6 +51,9 @@ public class ContaContabilSaldoServiceImpl extends GenericServiceImpl<ContaConta |
49 | 51 | private ContaContabilService contaContabilService; |
50 | 52 | |
51 | 53 | @Autowired |
54 | + private DominioService dominioService; | |
55 | + | |
56 | + @Autowired | |
52 | 57 | private ContaContabilMovimentoService contaContabilMovimentoService; |
53 | 58 | |
54 | 59 | /** |
... | ... | @@ -88,6 +93,23 @@ public class ContaContabilSaldoServiceImpl extends GenericServiceImpl<ContaConta |
88 | 93 | return true; |
89 | 94 | } |
90 | 95 | |
96 | + @Override | |
97 | + public boolean fechaSaldoContasContabeisTipoPermanente(Organizacao organizacao) { | |
98 | + Dominio tipoMaterial = this.dominioService.findByChaveAndCodigo(Dominio.TIPO_MATERIAL, Dominio.TIPO_MATERIAL_PERMANENTE); | |
99 | + Collection<ContaContabil> contasContabeis = this.contaContabilService.findAllByOrganizacaoAndTipoMaterial(organizacao, tipoMaterial); | |
100 | + Calendar mesReferencia = (Calendar) organizacao.getDataReferenciaVigente().clone(); | |
101 | + | |
102 | + for (ContaContabil conta : contasContabeis) { | |
103 | + if (conta.getId() != null && isReferenciaMaiorQueAnterior(conta.getContaContabilSaldoAnterior().getDataReferencia(), mesReferencia)) { | |
104 | + fechaSaldoConta(conta, mesReferencia); | |
105 | + } | |
106 | + } | |
107 | + this.flush(); | |
108 | + | |
109 | + organizacao.setDataReferenciaVigente(mesReferencia); | |
110 | + return true; | |
111 | + } | |
112 | + | |
91 | 113 | /** |
92 | 114 | * |
93 | 115 | * <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p> | ... | ... |
cit-adm-materiais-api/src/main/java/br/com/centralit/api/service/impl/ContaContabilServiceImpl.java
... | ... | @@ -653,4 +653,12 @@ public class ContaContabilServiceImpl extends GenericServiceImpl<ContaContabil, |
653 | 653 | return this.contaContabilDao.findByMaterial(materialId); |
654 | 654 | } |
655 | 655 | |
656 | + /** | |
657 | + * {@inheritDoc} | |
658 | + */ | |
659 | + @Override | |
660 | + public Collection<ContaContabil> findAllByOrganizacaoAndTipoMaterial(Organizacao organizacao, Dominio tipoMaterial) { | |
661 | + return this.contaContabilDao.findAllByOrganizacaoAndTipoMaterial(organizacao, tipoMaterial); | |
662 | + } | |
663 | + | |
656 | 664 | } |
657 | 665 | \ No newline at end of file | ... | ... |
cit-adm-materiais-web/src/main/java/br/com/centralit/controller/OrganizacaoAdmMateriaisController.java
1 | 1 | package br.com.centralit.controller; |
2 | 2 | |
3 | -import java.util.Calendar; | |
4 | -import java.util.Map; | |
5 | - | |
6 | 3 | import javax.servlet.http.HttpServletRequest; |
7 | 4 | |
8 | 5 | import org.springframework.beans.factory.annotation.Autowired; |
9 | -import org.springframework.security.core.context.SecurityContextHolder; | |
10 | 6 | import org.springframework.stereotype.Controller; |
11 | -import org.springframework.web.bind.annotation.RequestBody; | |
12 | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
13 | -import org.springframework.web.bind.annotation.RequestMethod; | |
14 | -import org.springframework.web.bind.annotation.ResponseBody; | |
15 | 8 | |
16 | -import br.com.centralit.api.model.MyMensagemRetorno; | |
17 | -import br.com.centralit.api.model.MyRetornoStatus; | |
18 | 9 | import br.com.centralit.api.service.ContaContabilSaldoService; |
19 | 10 | import br.com.centralit.api.service.ModuloService; |
20 | 11 | import br.com.centralit.api.service.OrganizacaoService; |
21 | -import br.com.centralit.api.util.ClientRest; | |
22 | -import br.com.centralit.framework.json.ResponseBodyWrapper; | |
23 | -import br.com.centralit.framework.json.Views; | |
24 | -import br.com.centralit.framework.model.Modulo; | |
25 | -import br.com.centralit.framework.model.Organizacao; | |
26 | -import br.com.centralit.framework.model.Usuario; | |
27 | -import br.com.centralit.framework.util.UtilObjeto; | |
28 | 12 | |
29 | 13 | /** |
30 | 14 | * <p> |
... | ... | @@ -78,87 +62,4 @@ public class OrganizacaoAdmMateriaisController { |
78 | 62 | @Autowired |
79 | 63 | private HttpServletRequest request; |
80 | 64 | |
81 | - /** | |
82 | - * | |
83 | - * <p> | |
84 | - * <b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a> | |
85 | - * </p> | |
86 | - * | |
87 | - * <p> | |
88 | - * <b>Regra(s) de negócio:</b> <a href="LINK_PORTAL">NUMERO_REGRA_DE_NEGOCIO</a> | |
89 | - * </p> | |
90 | - * | |
91 | - * 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. | |
92 | - * | |
93 | - * @author geovane.filho | |
94 | - * | |
95 | - * @param request | |
96 | - * Pedido de fechamento do mes contendo a organização e o tipo de depreciação a ser realizado | |
97 | - * @return <code>ResponseBodyWrapper</code> contendo a atualização da organização após o fechamento | |
98 | - */ | |
99 | - @RequestMapping(value = "/fecharMes", method = RequestMethod.POST) | |
100 | - @ResponseBody | |
101 | - public ResponseBodyWrapper fecharMes(@RequestBody Map<String, Long> requisicaoFechamento) { | |
102 | - Usuario user = (Usuario) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | |
103 | - Organizacao organizacao = this.organizacaoService.find(requisicaoFechamento.get("organizacao")); | |
104 | - Long tipoDepreciacaoCodigo = requisicaoFechamento.get("tipoDepreciacao"); | |
105 | - | |
106 | - Modulo modulo = moduloService.moduloEstaAtivo(ClientRest.MODULO_PATRIMONIO); | |
107 | - | |
108 | - MyRetornoStatus retornoFechamentoBens = new MyRetornoStatus(); | |
109 | - | |
110 | - MyRetornoStatus retornoBensNaEstruturaAlmoxarifado = new MyRetornoStatus(); | |
111 | - | |
112 | - if (UtilObjeto.isReferencia(modulo)) { | |
113 | - | |
114 | - ClientRest clientRestBemNaEstrutura = new ClientRest(request, modulo); | |
115 | - clientRestBemNaEstrutura.addParametro("idOrganizacao", organizacao.getId().toString()); | |
116 | - retornoBensNaEstruturaAlmoxarifado = clientRestBemNaEstrutura.getResponse("bemPatrimonial/validarBensNaEstruturaAlmoxarifado", MyRetornoStatus.class); | |
117 | - retornoBensNaEstruturaAlmoxarifado.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.error, "MSG.BENS_NA_ESTRUTURA_ALMOXARIFADO")); | |
118 | - | |
119 | - if(!retornoBensNaEstruturaAlmoxarifado.status) { | |
120 | - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retornoBensNaEstruturaAlmoxarifado, Views.EstruturaOrganizacionalEditView.class); | |
121 | - return responseBody; | |
122 | - } | |
123 | - | |
124 | - ClientRest clientRest = new ClientRest(request, modulo); | |
125 | - clientRest.addParametro("idOrganizacao", organizacao.getId().toString()); | |
126 | - clientRest.addParametro("userId", user.getId().toString()); | |
127 | - | |
128 | - retornoFechamentoBens = clientRest.getResponse("bemPatrimonial/fechaValorBem", MyRetornoStatus.class); | |
129 | - } | |
130 | - | |
131 | - MyRetornoStatus retornoFechamentoContas = new MyRetornoStatus(); | |
132 | - retornoFechamentoContas.status = this.contaContabilSaldoService.fechaSaldoContasContabeis(organizacao); | |
133 | - | |
134 | - if (retornoFechamentoBens.status && retornoFechamentoContas.status) { | |
135 | - MyRetornoStatus retornoDepreciacao = new MyRetornoStatus(); | |
136 | - | |
137 | - // Gera a depreciação dos bens patrimoniais de acordo com o tipo | |
138 | - if (UtilObjeto.isReferencia(modulo)) { | |
139 | - | |
140 | - ClientRest clientRest = new ClientRest(request, modulo); | |
141 | - clientRest.addParametro("idOrganizacao", organizacao.getId().toString()); | |
142 | - clientRest.addParametro("codigoTipoDepreciacao", tipoDepreciacaoCodigo.toString()); | |
143 | - clientRest.addParametro("userId", user.getId().toString()); | |
144 | - | |
145 | - retornoDepreciacao = clientRest.getResponse("depreciacao/geraDepreciacao", MyRetornoStatus.class); | |
146 | - } | |
147 | - | |
148 | - if (retornoDepreciacao.status) { // Se a depreciação foi realizada com sucesso eu atualizo o mês de referencia | |
149 | - retornoFechamentoContas.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.success, "MSG.SUCESSO_DEPRECIACAO")); | |
150 | - organizacao.getDataReferenciaVigente().add(Calendar.MONTH, 1); | |
151 | - this.organizacaoService.merge(organizacao); | |
152 | - retornoFechamentoContas.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.success, "MSG.SUCESSO_MES_REFERENCIA")); | |
153 | - } else { | |
154 | - retornoFechamentoContas.status = retornoDepreciacao.status; | |
155 | - retornoFechamentoContas.mensagens.addAll(retornoDepreciacao.mensagens); | |
156 | - } | |
157 | - } | |
158 | - | |
159 | - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retornoFechamentoContas, Views.EstruturaOrganizacionalEditView.class); | |
160 | - | |
161 | - return responseBody; | |
162 | - } | |
163 | - | |
164 | 65 | } |
165 | 66 | \ No newline at end of file | ... | ... |
cit-adm-materiais-web/src/main/webapp/assets/js/angular/custom/controller/MesReferenciaController.js
1 | 1 | 'use strict'; |
2 | 2 | |
3 | -citApp.controller('MesReferenciaController', ['$scope', 'OrganizacaoRepository', 'DominioRepository', '$filter', '$translate', 'DepreciacaoRepository', 'OrganizacaoAdmMateriaisRepository', function MesReferenciaController($scope, OrganizacaoRepository, DominioRepository, $filter, $translate, DepreciacaoRepository, OrganizacaoAdmMateriaisRepository) { | |
3 | +citApp.controller('MesReferenciaController', ['$scope', 'OrganizacaoRepository', 'DominioRepository', '$filter', '$translate', 'DepreciacaoRepository', 'OrganizacaoPatrimonioRepository', function MesReferenciaController($scope, OrganizacaoRepository, DominioRepository, $filter, $translate, DepreciacaoRepository, OrganizacaoPatrimonioRepository) { | |
4 | 4 | |
5 | 5 | $scope.setLoadingGet(true); |
6 | 6 | |
... | ... | @@ -36,7 +36,7 @@ citApp.controller('MesReferenciaController', ['$scope', 'OrganizacaoRepository', |
36 | 36 | |
37 | 37 | $scope.setLoadingSalva(true); |
38 | 38 | |
39 | - OrganizacaoAdmMateriaisRepository.fecharMes($scope.organizacao.id, $scope.tipoDepreciacaoObj).then(function(result) { | |
39 | + OrganizacaoPatrimonioRepository.fecharMes($scope.organizacao.id, $scope.tipoDepreciacaoObj).then(function(result) { | |
40 | 40 | //Caso a data de referencia não tenha mudado o mês não foi fechado |
41 | 41 | //if ($scope.dataVigente == $filter('date')(converterStringEmDate(result.originalElement.dataReferenciaVigente), "MMMM/yyyy")) { |
42 | 42 | if (!result.originalElement.status) { | ... | ... |