Commit e74c816d9b0697cdb77855e09a8d2cea60f9c770
1 parent
79c6c4a7
Exists in
master
[Redmine Atendimento #4648]Edição transferencia
Showing
2 changed files
with
153 additions
and
26 deletions
Show diff stats
citgrp-patrimonio-api/src/main/java/br/com/centralit/api/service/impl/TransferenciaServiceImpl.java
@@ -177,6 +177,119 @@ public class TransferenciaServiceImpl extends GenericServiceImpl<Transferencia, | @@ -177,6 +177,119 @@ public class TransferenciaServiceImpl extends GenericServiceImpl<Transferencia, | ||
177 | // GERA CONTA CONTÁBIL MOVIMENTO | 177 | // GERA CONTA CONTÁBIL MOVIMENTO |
178 | this.contaContabilMovimentoPatrimonioService.geraMovimento(transferencia); | 178 | this.contaContabilMovimentoPatrimonioService.geraMovimento(transferencia); |
179 | } | 179 | } |
180 | + | ||
181 | + private void atualizarRegistroTransferencia(Transferencia transferencia, List<Transferencia> listaTransferenciaSalva) { | ||
182 | + | ||
183 | + // VALIDA CAMPO OBRIGATÓRIO DA ENTIDADE | ||
184 | + if (UtilObjeto.isReferencia(this.validator)) { | ||
185 | + if (transferencia.getDataTransferencia() == null) { | ||
186 | + transferencia.setDataTransferencia(Calendar.getInstance()); | ||
187 | + } | ||
188 | + this.validarEntidade(transferencia, this.validator); | ||
189 | + } | ||
190 | + | ||
191 | + // MONTA OS DADOS DO OBJETO TRANSFERÊNCIA | ||
192 | + this.montarDadosTransferencia(transferencia, false); | ||
193 | + | ||
194 | + // REMOVER DETENTOR DO BEM NA TRANSFERENCIA | ||
195 | + if (UtilObjeto.isReferencia(transferencia.isRemoveDetentor()) && transferencia.isRemoveDetentor() && !UtilColecao.isVazio(transferencia.getSaidaTemporariaItens())) { | ||
196 | + for (TransferenciaItem item : transferencia.getSaidaTemporariaItens()) { | ||
197 | + | ||
198 | + if (UtilObjeto.isReferencia(item.getBemPatrimonial().getDetentor())) { | ||
199 | + // INSERI DATA DE FIM ATRIBUIACAO PARA A DEFINICAO DE DETENTOR | ||
200 | + definicaoDetentorService.setFimAtribuicao(item.getBemPatrimonial().getId(), item.getBemPatrimonial().getDetentor().getId(), transferencia.getDataTransferencia()); | ||
201 | + } | ||
202 | + | ||
203 | + // REMOVE O DETENTOR E RESPONSAVEL | ||
204 | + bemPatrimonialService.removeDetentorBemPatrimonialTransferencia(item.getBemPatrimonial()); | ||
205 | + } | ||
206 | + } | ||
207 | + | ||
208 | + updateTransferenciaGeraTermo(transferencia, listaTransferenciaSalva); | ||
209 | + | ||
210 | + // GERA HISTÓRICO DO BEM PATRIMONIAL | ||
211 | + this.historicoBempatrimonialService.gerarHistoricoBemPatrimonialTransferencia(transferencia); | ||
212 | + | ||
213 | + // GERA CONTA CONTÁBIL MOVIMENTO | ||
214 | + this.contaContabilMovimentoPatrimonioService.geraMovimento(transferencia); | ||
215 | + } | ||
216 | + | ||
217 | + private void updateTransferenciaGeraTermo(Transferencia transferencia, List<Transferencia> listaTransferenciaSalva) { | ||
218 | + | ||
219 | + Long idUltimaEstrutura = 0L; | ||
220 | + | ||
221 | + List<TransferenciaItem> transferenciaItemListTemp = new ArrayList<TransferenciaItem>(); | ||
222 | + // Cria uma lista de transferência item a partir da lista da transferência | ||
223 | + ArrayList<TransferenciaItem> transferenciaItemListOrdenadoEstrutura = new ArrayList<TransferenciaItem>(transferencia.getSaidaTemporariaItens()); | ||
224 | + | ||
225 | + if(!UtilColecao.isVazio(transferenciaItemListOrdenadoEstrutura) && transferenciaItemListOrdenadoEstrutura.size() == 1){ | ||
226 | + List<TransferenciaItem> transferenciaItens = this.transferenciaItemService.buscarTransferenciaItens(transferencia.getId()); | ||
227 | + for (TransferenciaItem transferenciaItem : transferenciaItens) { | ||
228 | + for (TransferenciaItem transferenciaOrdem : transferenciaItemListOrdenadoEstrutura) { | ||
229 | + if(transferenciaItem.getBemPatrimonial().getId() == transferenciaOrdem.getBemPatrimonial().getId()){ | ||
230 | + transferencia.setSaidaTemporariaItens(transferenciaItens); | ||
231 | + } | ||
232 | + } | ||
233 | + } | ||
234 | + this.merge(transferencia); | ||
235 | + }else{ | ||
236 | + // Ordena a lista de transferência item por estrutura organizacional | ||
237 | + Collections.sort((List<TransferenciaItem>) transferenciaItemListOrdenadoEstrutura); | ||
238 | + | ||
239 | + // Percorre a lista de transferência item ordenada e gera o termo de responsabilidade por estrutura organizacional | ||
240 | + for (Iterator iterator = transferenciaItemListOrdenadoEstrutura.iterator(); iterator.hasNext();) { | ||
241 | + | ||
242 | + TransferenciaItem transferenciaItem = (TransferenciaItem) iterator.next(); | ||
243 | + | ||
244 | + // Valida se o idUltimaEstrutura da estrutura organizacional é o mesmo da iteração. | ||
245 | + if (idUltimaEstrutura.equals(0L) || idUltimaEstrutura.equals(transferenciaItem.getEstruturaOrganizacionalOrigem().getId())) { | ||
246 | + | ||
247 | + idUltimaEstrutura = transferenciaItem.getEstruturaOrganizacionalOrigem().getId(); | ||
248 | + transferenciaItemListTemp.add(transferenciaItem); | ||
249 | + } else { | ||
250 | + boolean salvarNovaTransferencia = true; | ||
251 | + for (TransferenciaItem transferenciaItemTemp : transferenciaItemListTemp) { | ||
252 | + if(transferenciaItemTemp.getEstruturaOrganizacionalOrigem().getId() == transferencia.getEstruturaOrganizacionalDestino().getId()){ | ||
253 | + salvarNovaTransferencia = false; | ||
254 | + break; | ||
255 | + } | ||
256 | + } | ||
257 | + | ||
258 | + // SALVA A TRANSFERÊNCIA | ||
259 | + if(salvarNovaTransferencia){ | ||
260 | + Transferencia transferenciaSave = geraTransferenciaInterna(transferencia, transferenciaItemListTemp); | ||
261 | + this.transferenciaDao.save(transferenciaSave); | ||
262 | + this.salvarTermo(transferenciaSave, this.estruturaOrganizacionalService.getReference(idUltimaEstrutura)); | ||
263 | + if (listaTransferenciaSalva != null) { | ||
264 | + listaTransferenciaSalva.add(transferenciaSave); | ||
265 | + } | ||
266 | + } | ||
267 | + idUltimaEstrutura = transferenciaItem.getEstruturaOrganizacionalOrigem().getId(); | ||
268 | + transferenciaItemListTemp = new ArrayList<TransferenciaItem>(); | ||
269 | + transferenciaItemListTemp.add(transferenciaItem); | ||
270 | + } | ||
271 | + } | ||
272 | + | ||
273 | + boolean salvarNovaTransferencia = true; | ||
274 | + for (TransferenciaItem transferenciaItemTemp : transferenciaItemListTemp) { | ||
275 | + if(transferenciaItemTemp.getEstruturaOrganizacionalOrigem().getId() == transferencia.getEstruturaOrganizacionalDestino().getId()){ | ||
276 | + salvarNovaTransferencia = false; | ||
277 | + break; | ||
278 | + } | ||
279 | + } | ||
280 | + if(salvarNovaTransferencia){ | ||
281 | + Transferencia transferenciaSave = geraTransferenciaInterna(transferencia, transferenciaItemListTemp); | ||
282 | + this.transferenciaDao.save(transferenciaSave); | ||
283 | + configurarCodigo(transferenciaSave); | ||
284 | + this.salvarTermo(transferenciaSave, this.estruturaOrganizacionalService.getReference(idUltimaEstrutura)); | ||
285 | + if (listaTransferenciaSalva != null) { | ||
286 | + listaTransferenciaSalva.add(transferencia); | ||
287 | + } | ||
288 | + | ||
289 | + } | ||
290 | + | ||
291 | + } | ||
292 | + } | ||
180 | 293 | ||
181 | private void saveTransferenciaGeraTermo(Transferencia transferencia, List<Transferencia> listaTransferenciaSalva) { | 294 | private void saveTransferenciaGeraTermo(Transferencia transferencia, List<Transferencia> listaTransferenciaSalva) { |
182 | 295 | ||
@@ -322,7 +435,7 @@ public class TransferenciaServiceImpl extends GenericServiceImpl<Transferencia, | @@ -322,7 +435,7 @@ public class TransferenciaServiceImpl extends GenericServiceImpl<Transferencia, | ||
322 | 435 | ||
323 | for (TransferenciaItem transferenciaItem : transferencia.getSaidaTemporariaItens()) { | 436 | for (TransferenciaItem transferenciaItem : transferencia.getSaidaTemporariaItens()) { |
324 | HistoricoBemPatrimonial ultimoHistoricoBem = historicoBempatrimonialService.buscarUltimoHistoricoBem(transferenciaItem.getBemPatrimonial(), transferencia.getId()); | 437 | HistoricoBemPatrimonial ultimoHistoricoBem = historicoBempatrimonialService.buscarUltimoHistoricoBem(transferenciaItem.getBemPatrimonial(), transferencia.getId()); |
325 | - if (UtilObjeto.isReferencia(transferencia.getId())) { | 438 | + if (ultimoHistoricoBem != null && UtilObjeto.isReferencia(transferencia.getId())) { |
326 | ultimoHistoricoBem.setDataOperacao(transferencia.getDataTransferencia()); | 439 | ultimoHistoricoBem.setDataOperacao(transferencia.getDataTransferencia()); |
327 | this.historicoBempatrimonialService.merge(ultimoHistoricoBem); | 440 | this.historicoBempatrimonialService.merge(ultimoHistoricoBem); |
328 | break; | 441 | break; |
@@ -765,7 +878,7 @@ public class TransferenciaServiceImpl extends GenericServiceImpl<Transferencia, | @@ -765,7 +878,7 @@ public class TransferenciaServiceImpl extends GenericServiceImpl<Transferencia, | ||
765 | // SALVA A TRANSFERÊNCIA | 878 | // SALVA A TRANSFERÊNCIA |
766 | 879 | ||
767 | List<Transferencia> listaTransferenciaSalva = new ArrayList<Transferencia>(); | 880 | List<Transferencia> listaTransferenciaSalva = new ArrayList<Transferencia>(); |
768 | - this.salvarNovoRegistro(transferencia, listaTransferenciaSalva); | 881 | + this.atualizarRegistroTransferencia(transferencia, listaTransferenciaSalva); |
769 | // this.transferenciaDao.merge(transferencia); | 882 | // this.transferenciaDao.merge(transferencia); |
770 | 883 | ||
771 | this.contaContabilMovimentoPatrimonioService.alterarMovimentoTransferencia(transferencia); | 884 | this.contaContabilMovimentoPatrimonioService.alterarMovimentoTransferencia(transferencia); |
citgrp-patrimonio-web/src/main/webapp/assets/js/angular/custom/controller/TransferenciaController.js
@@ -175,6 +175,7 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | @@ -175,6 +175,7 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | ||
175 | $scope.listaBemPatrimonialTemp = []; | 175 | $scope.listaBemPatrimonialTemp = []; |
176 | $scope.saidaTemp = null; | 176 | $scope.saidaTemp = null; |
177 | $scope.referenciaVigente = null; | 177 | $scope.referenciaVigente = null; |
178 | + $scope.salvarEdicaoUltimoItem = false; | ||
178 | $timeout(function(){ | 179 | $timeout(function(){ |
179 | $scope.transferenciaForm.$submitted = true; | 180 | $scope.transferenciaForm.$submitted = true; |
180 | $scope.transferenciaForm.$setPristine(); | 181 | $scope.transferenciaForm.$setPristine(); |
@@ -308,21 +309,25 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | @@ -308,21 +309,25 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | ||
308 | 309 | ||
309 | $scope.transferencia.removeDetentor = removerDetentor; | 310 | $scope.transferencia.removeDetentor = removerDetentor; |
310 | 311 | ||
311 | - TransferenciaRepository.validarTransferenciaMesmoDia($scope.transferencia).then(function(result) { | ||
312 | - if(result){ | ||
313 | - $scope.setLoading(false); | ||
314 | - $scope.$openModalConfirm({ | ||
315 | - message: $translate.instant("PATRIMONIO.VALIDACAO.TRANSFERENCIA_MESMO_DIA"), | ||
316 | - callback: function () { | ||
317 | - $scope.setLoading(true); | ||
318 | - $scope.$modalConfirmInstance.dismiss('cancel'); | ||
319 | - saveAposValidacoes(result); | ||
320 | - } | ||
321 | - }); | ||
322 | - } else { | ||
323 | - saveAposValidacoes(result); | ||
324 | - } | ||
325 | - }); | 312 | + if($scope.salvarEdicaoUltimoItem){ |
313 | + saveAposValidacoes(); | ||
314 | + }else{ | ||
315 | + TransferenciaRepository.validarTransferenciaMesmoDia($scope.transferencia).then(function(result) { | ||
316 | + if(result){ | ||
317 | + $scope.setLoading(false); | ||
318 | + $scope.$openModalConfirm({ | ||
319 | + message: $translate.instant("PATRIMONIO.VALIDACAO.TRANSFERENCIA_MESMO_DIA"), | ||
320 | + callback: function () { | ||
321 | + $scope.setLoading(true); | ||
322 | + $scope.$modalConfirmInstance.dismiss('cancel'); | ||
323 | + saveAposValidacoes(result); | ||
324 | + } | ||
325 | + }); | ||
326 | + } else { | ||
327 | + saveAposValidacoes(result); | ||
328 | + } | ||
329 | + }); | ||
330 | + } | ||
326 | 331 | ||
327 | } else { | 332 | } else { |
328 | 333 | ||
@@ -358,11 +363,15 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | @@ -358,11 +363,15 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | ||
358 | 363 | ||
359 | 364 | ||
360 | $scope.setLoading(false); | 365 | $scope.setLoading(false); |
361 | - $scope.showAlert("success", $translate.instant("MSG.MG001")); | ||
362 | - if(!$scope.edit){ | ||
363 | - $scope.gerarReport(); | 366 | + if(!$scope.salvarEdicaoUltimoItem){ |
367 | + $scope.showAlert("success", $translate.instant("MSG.MG001")); | ||
368 | + if(!$scope.edit){ | ||
369 | + $scope.gerarReport(); | ||
370 | + } | ||
371 | + $scope.resetForm(); | ||
372 | + }else{ | ||
373 | + $scope.salvarEdicaoUltimoItem = false; | ||
364 | } | 374 | } |
365 | - $scope.resetForm(); | ||
366 | } | 375 | } |
367 | }); | 376 | }); |
368 | }; | 377 | }; |
@@ -467,12 +476,12 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | @@ -467,12 +476,12 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | ||
467 | 476 | ||
468 | $scope.permiteExcluirItem = function() { | 477 | $scope.permiteExcluirItem = function() { |
469 | var deferred = $q.defer(); | 478 | var deferred = $q.defer(); |
470 | - if($scope.listaBemPatrimonialTemp.length == $scope.listaItensSelecionados.length){ | ||
471 | - $scope.showAlert("error", $translate.instant("PATRIMONIO.VALIDACAO.REMOVER_TODOS_ITEM_TRASNFERENCIA")); | 479 | + if($scope.transferencia.id && $scope.listaBemPatrimonialTemp.length == $scope.listaItensSelecionados.length){ |
480 | + $scope.showAlert("warning", $translate.instant("PATRIMONIO.VALIDACAO.REMOVER_TODOS_ITEM_TRASNFERENCIA")); | ||
472 | deferred.resolve(false); | 481 | deferred.resolve(false); |
473 | }else{ | 482 | }else{ |
474 | - if($scope.listaBemPatrimonialTemp.length == 1 && $scope.transferencia.id){ | ||
475 | - $scope.showAlert("error", $translate.instant("PATRIMONIO.VALIDACAO.REMOVER_ULTIMO_ITEM_TRASNFERENCIA")); | 483 | + if($scope.transferencia.id && $scope.listaBemPatrimonialTemp.length == 1 && $scope.transferencia.id){ |
484 | + $scope.showAlert("warning", $translate.instant("PATRIMONIO.VALIDACAO.REMOVER_ULTIMO_ITEM_TRASNFERENCIA")); | ||
476 | deferred.resolve(false); | 485 | deferred.resolve(false); |
477 | }else{ | 486 | }else{ |
478 | deferred.resolve(true); | 487 | deferred.resolve(true); |
@@ -487,7 +496,12 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | @@ -487,7 +496,12 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' | ||
487 | TransferenciaItemRepository.findTransferenciaItemBemPatrimonialTransferencia(bemSelecionado.id, $scope.transferencia.id).then(function(result) { | 496 | TransferenciaItemRepository.findTransferenciaItemBemPatrimonialTransferencia(bemSelecionado.id, $scope.transferencia.id).then(function(result) { |
488 | TransferenciaItemRepository.removerItem(result.id).then(function(result) { | 497 | TransferenciaItemRepository.removerItem(result.id).then(function(result) { |
489 | $scope.showAlert('success', $translate.instant('MSG.EXCLUSAO_SUCESSO'), " ", false); | 498 | $scope.showAlert('success', $translate.instant('MSG.EXCLUSAO_SUCESSO'), " ", false); |
490 | - $scope.setLoading(false); | 499 | + if($scope.listaBemPatrimonialTemp.length == 1){ |
500 | + $scope.salvarEdicaoUltimoItem = true; | ||
501 | + $scope.saveOrUpdate(false); | ||
502 | + }else{ | ||
503 | + $scope.setLoading(false); | ||
504 | + } | ||
491 | }); | 505 | }); |
492 | }); | 506 | }); |
493 | } | 507 | } |