Commit 7d01b02f1ae919e6194e8580a89fde72833010fe

Authored by Ciro Junior
1 parent a45a7f92
Exists in master

[Redmine #4235]

Commit final
cit-contratos-api/src/main/java/br/com/centralit/api/model/ContratoEnvolvido.java
... ... @@ -55,7 +55,7 @@ import br.com.centralit.framework.model.arquitetura.PersistentObjectAudit;
55 55 */
56 56 @Entity
57 57 @Table(name = "cnt_cn_envolvido")
58   -@JsonIgnoreProperties({ "$checked" })
  58 +@JsonIgnoreProperties({ "$checked", "justificativasAnterioresLength" })
59 59 public class ContratoEnvolvido extends PersistentObjectAudit {
60 60  
61 61 /** Atributo serialVersionUID. */
... ...
cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/ContratoServiceImpl.java
... ... @@ -22,6 +22,7 @@ import br.com.centralit.api.model.Contrato;
22 22 import br.com.centralit.api.model.ContratoDocumento;
23 23 import br.com.centralit.api.model.ContratoEmpenho;
24 24 import br.com.centralit.api.model.ContratoEnvolvido;
  25 +import br.com.centralit.api.model.ContratoEnvolvidoJustificativa;
25 26 import br.com.centralit.api.model.ContratoItem;
26 27 import br.com.centralit.api.model.ContratoObservacao;
27 28 import br.com.centralit.api.model.ContratoValorPagamento;
... ... @@ -252,17 +253,16 @@ public class ContratoServiceImpl extends GenericServiceImpl<Contrato, Long> impl
252 253 }
253 254 }
254 255  
255   - // cria vinculo do contrato com as ctrtItens
  256 + // cria vinculo do contrato com os envolvidos
256 257 if (CollectionUtils.isNotEmpty(contrato.getCtrtEnvolvidos())){
257   -
258 258 for (ContratoEnvolvido contratoEnvolvido : contrato.getCtrtEnvolvidos()) {
259   -
260 259 contratoEnvolvido.setEnvolvido(this.colaboradorService.find(contratoEnvolvido.getEnvolvido().getId()));
261   -
262 260 contratoEnvolvido.setContrato(contrato);
263   -
264 261 if (CollectionUtils.isNotEmpty(contratoEnvolvido.getJustificativas())){
265   - contratoEnvolvido.setJustificativas(contratoEnvolvido.getJustificativas());
  262 + for(ContratoEnvolvidoJustificativa justificativa : contratoEnvolvido.getJustificativas()){
  263 + justificativa.setContratoEnvolvido(contratoEnvolvido);
  264 + justificativa.setAutor(this.usuarioService.find(justificativa.getAutor().getId()));
  265 + }
266 266 }
267 267 }
268 268 }
... ...
cit-contratos-web/src/main/webapp/assets/js/angular/custom/controller/ContratoController.js
... ... @@ -245,6 +245,17 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
245 245 return;
246 246 };
247 247  
  248 + if ($scope.contrato.id && $scope.contrato.ctrtEnvolvidos){
  249 + angular.forEach($scope.contrato.ctrtEnvolvidos, function(envolvido){
  250 + if (envolvido.justificativas.length === 0){
  251 + angular.forEach(envolvido.justificativas, function(justificativa){
  252 + delete justificativa.autor;
  253 + delete justificativa.dataCriacao;
  254 + });
  255 + }
  256 + });
  257 + }
  258 +
248 259 if ($scope.contrato.ctrtValoresPagamento && $scope.contrato.ctrtValoresPagamento.length > 0){
249 260 if (!validarContratoValoresPagamento()){
250 261 return;
... ... @@ -297,16 +308,6 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
297 308 $scope.showAlert('error', $translate.instant('VALIDACAO.CONTRATO_EXIGE_MINIMO_TRES_ENVOLVIDOS'));
298 309 return false;
299 310 }
300   -
301   - if($scope.contrato.id && $scope.hasAlteracaoEnvolvido){
302   - $scope.showAlert('error', $translate.instant('CONTRATOS.VALIDACAO.ALTERACAO_ENVOLVIDOS_EXIGE_JUSTIFICATIVA'));
303   - return false;
304   - } else if ($scope.contrato.ctrtEnvolvidos){
305   - angular.forEach($scope.contrato.ctrtEnvolvidos.justificativas, function(justificativa){
306   - delete justificativa.autor;
307   - delete justificativa.dataCriacao;
308   - });
309   - }
310 311 return true;
311 312 };
312 313  
... ... @@ -1366,10 +1367,14 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1366 1367 // responsavel por abrir modal de adicao de um contratoEnvolvido
1367 1368 $scope.openModalContratoEnvolvido = function() {
1368 1369  
1369   - //filtrarPapeisSelecionados();
1370   -
1371   - $scope.contratoEnvolvidoTemp = {};
1372 1370 $scope.editEnvolvido = true;
  1371 + $scope.contratoEnvolvidoTemp = {justificativas : []};
  1372 + $scope.contrato.ctrtEnvolvidos.forEach(function(item){
  1373 + if(item.$checked){
  1374 + item.$checked = false;
  1375 + }
  1376 + });
  1377 + filtrarPapeisSelecionados();
1373 1378 $scope.$openModal('dialog_envolvido.html', 'lg');
1374 1379 };
1375 1380  
... ... @@ -1383,7 +1388,8 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1383 1388  
1384 1389 formDialogEnvolvido.$submitted = true;
1385 1390 if($scope.contrato.id && $scope.hasAlteracaoEnvolvido){
1386   - if($scope.contratoEnvolvidoTemp.justificativas.length === 0 || $scope.contratoEnvolvidoTemp.justificativas.length === $scope.justificativasAnterioresLength){
  1391 + if($scope.contratoEnvolvidoTemp.justificativas.length === 0 ||
  1392 + $scope.contratoEnvolvidoTemp.justificativas.length === $scope.contratoEnvolvidoTemp.justificativasAnterioresLength){
1387 1393 $scope.showAlert('error', $translate.instant('CONTRATOS.VALIDACAO.ALTERACAO_ENVOLVIDOS_EXIGE_JUSTIFICATIVA'));
1388 1394 return;
1389 1395 }
... ... @@ -1408,10 +1414,11 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1408 1414  
1409 1415 $scope.contratoEnvolvidoTemp = {};
1410 1416 $scope.justificativaTemp = {};
  1417 + $scope.hasAlteracaoEnvolvido = false;
1411 1418 if (continuarEditando) {
1412 1419 formDialogEnvolvido.$submitted = false;
1413 1420 formDialogEnvolvido.$setPristine();
1414   - //filtrarPapeisSelecionados();
  1421 + filtrarPapeisSelecionados();
1415 1422 } else {
1416 1423 $scope.$modalInstance.dismiss('cancel');
1417 1424 }
... ... @@ -1421,9 +1428,8 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1421 1428  
1422 1429 form.$submitted = true;
1423 1430  
1424   - if (form.$invalid) {
1425   - //Mensagem de erro de campos obrigatorios nao preenchidos
1426   - $scope.showAlert('error', $translate.instant('VALIDACAO.ALERTA_OBRIGATORIOS'), " ", false);
  1431 + if ($scope.justificativaTemp.descricao === '' || $scope.justificativaTemp.descricao == undefined) {
  1432 + $scope.showAlert('error', $translate.instant('CONTRATOS.VALIDACAO.ALTERACAO_ENVOLVIDOS_EXIGE_JUSTIFICATIVA'));
1427 1433 return;
1428 1434 }
1429 1435 if ($scope.contratoEnvolvidoTemp.justificativas){
... ... @@ -1432,25 +1438,28 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1432 1438 $scope.contratoEnvolvidoTemp.justificativas.push($scope.justificativaTemp);
1433 1439 }
1434 1440 $scope.justificativaTemp = {};
1435   - $scope.hasAlteracaoEnvolvido = false;
1436 1441 };
1437 1442  
1438   -// function filtrarPapeisSelecionados() {
1439   -// if ($scope.contrato.ctrtEnvolvidos && $scope.contrato.ctrtEnvolvidos.length > 0){
1440   -//
1441   -// var dominiosPapelEnvolvidoContrato = [];
1442   -// $scope.contrato.ctrtEnvolvidos.forEach(function(item){
1443   -// dominiosPapelEnvolvidoContrato.push(item.dominioPapelEnvolvidoContrato);
1444   -// });
1445   -//
1446   -// $scope.dominioPapelEnvolvidoList = $filter('idNotEqualDominio')($scope.dominioPapelEnvolvidoListFixa, dominiosPapelEnvolvidoContrato);
1447   -//
1448   -// if ($scope.dominioPapelEnvolvidoList && $scope.dominioPapelEnvolvidoList.length === 0){
1449   -// $scope.showAlert('warning', $translate.instant('CONTRATOS.MSG.TODOS_PAPEIS_ENVOLVIDOS_ADICIONADOS'));
1450   -// return;
1451   -// }
1452   -// }
1453   -// };
  1443 + function filtrarPapeisSelecionados() {
  1444 + if ($scope.contrato.ctrtEnvolvidos && $scope.contrato.ctrtEnvolvidos.length > 0){
  1445 +
  1446 + var dominiosPapelEnvolvidoContrato = [];
  1447 + $scope.contrato.ctrtEnvolvidos.forEach(function(item){
  1448 + if(!item.$checked){
  1449 + dominiosPapelEnvolvidoContrato.push(item.dominioPapelEnvolvidoContrato);
  1450 + }
  1451 + });
  1452 +
  1453 + $scope.dominioPapelEnvolvidoList = $filter('idNotEqualDominio')($scope.dominioPapelEnvolvidoListFixa, dominiosPapelEnvolvidoContrato);
  1454 +
  1455 + if($scope.editEnvolvido){
  1456 + if ($scope.dominioPapelEnvolvidoList && $scope.dominioPapelEnvolvidoList.length === 0){
  1457 + $scope.showAlert('warning', $translate.instant('CONTRATOS.MSG.TODOS_PAPEIS_ENVOLVIDOS_ADICIONADOS'));
  1458 + return;
  1459 + }
  1460 + }
  1461 + }
  1462 + };
1454 1463  
1455 1464 //responsavel por remover um/ou mais item(ns) de contrato
1456 1465 $scope.removerContratoEnvolvido = function (){
... ... @@ -1497,10 +1506,6 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1497 1506 }
1498 1507  
1499 1508 $scope.dominioPapelEnvolvidoList.push(papelExcluido);
1500   -
1501   - if ($scope.contrato.id) {
1502   - $scope.hasAlteracaoEnvolvido = true;
1503   - }
1504 1509 }
1505 1510 });
1506 1511 };
... ... @@ -1536,9 +1541,7 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1536 1541 };
1537 1542  
1538 1543 // Responsavel por abrir modal de envolvido para edicao ou visualizacao do item selecionado
1539   - $scope.abrirContratoEnvolvido = function(edit) {
1540   -
1541   - //filtrarPapeisSelecionados();
  1544 + $scope.visualizarEditarContratoEnvolvido = function(edit) {
1542 1545  
1543 1546 $scope.editEnvolvido = edit;
1544 1547 $scope.contratoEnvolvidoTemp = null;
... ... @@ -1549,12 +1552,16 @@ citApp.controller('ContratoController', ['$scope', '$filter', 'FileUploader', 'C
1549 1552 return;
1550 1553 }
1551 1554 $scope.justificativaTemp = {};
1552   - $scope.justificativasAnterioresLength = $scope.contratoEnvolvidoTemp.justificativas.length;
1553   -
1554   - if ($scope.contrato.id) {
  1555 + if($scope.contratoEnvolvidoTemp.justificativas){
  1556 + $scope.contratoEnvolvidoTemp.justificativasAnterioresLength = $scope.contratoEnvolvidoTemp.justificativas.length;
  1557 + } else {
  1558 + $scope.contratoEnvolvidoTemp.justificativasAnterioresLength = 0;
  1559 + $scope.contratoEnvolvidoTemp.justificativas = [];
  1560 + }
  1561 + if($scope.contrato.id){
1555 1562 $scope.hasAlteracaoEnvolvido = edit;
1556 1563 }
1557   -
  1564 + filtrarPapeisSelecionados();
1558 1565 $timeout(function() {
1559 1566 $scope.$openModal('dialog_envolvido.html', 'lg');
1560 1567 });
... ...
cit-contratos-web/src/main/webapp/html/contrato/contratoPg5.html
... ... @@ -25,13 +25,13 @@
25 25 </button>
26 26  
27 27 <button title="{{$translate.instant('LABEL.VISUALIZAR')}}" alt="{{$translate.instant('LABEL.VISUALIZAR')}}" class="btn btn-clear" type="button"
28   - ng-click="abrirContratoEnvolvido(false);" ng-if="!acaoEmMassaEnvolvido">
  28 + ng-click="visualizarEditarContratoEnvolvido(false);" ng-if="!acaoEmMassaEnvolvido">
29 29 <i class="fa fa-search blue"></i>
30 30 <translate>LABEL.VISUALIZAR</translate>
31 31 </button>
32 32  
33 33 <button title="{{$translate.instant('LABEL.EDITAR')}}" alt="{{$translate.instant('LABEL.EDITAR')}}" ng-show="edit" class="btn btn-clear" type="button"
34   - ng-click="abrirContratoEnvolvido(true);" ng-if="!acaoEmMassaEnvolvido">
  34 + ng-click="visualizarEditarContratoEnvolvido(true);" ng-if="!acaoEmMassaEnvolvido">
35 35 <i class="fa fa-pencil blue"></i>
36 36 <translate>LABEL.EDITAR</translate>
37 37 </button>
... ...
cit-contratos-web/src/main/webapp/html/contrato/dialog_envolvido.html
... ... @@ -6,7 +6,7 @@
6 6 <translate>LABEL.ADICIONAR</translate>
7 7 </button>
8 8 <button title="{{$translate.instant('LABEL.ADICIONAR_NOVO')}}" alt="{{$translate.instant('LABEL.ADICIONAR_NOVO')}}"
9   - ng-click="adicionarContratoEnvolvido(formDialogEnvolvido, true)" ng-hide="editEnvolvido && hasAlteracaoEnvolvido" class="btn btn-clear" type="button">
  9 + ng-click="adicionarContratoEnvolvido(formDialogEnvolvido, true)" ng-show="editEnvolvido && !hasAlteracaoEnvolvido" class="btn btn-clear" type="button">
10 10 <i class="fa fa-save green"></i>
11 11 <translate>LABEL.ADICIONAR_CONTINUAR</translate>
12 12 </button>
... ... @@ -29,7 +29,7 @@
29 29 <div class="col-sm-6">
30 30 <auto-complete ng-find="findEnvolvido(value)" ng-item="item.pessoa.nome" ng-disabled="!editEnvolvido"
31 31 ng-id="contratoEnvolvidoTemp.envolvido" ng-label="LABEL.NOME_ENVOLVIDO" ng-model="contratoEnvolvidoTemp.envolvido"
32   - ng-disabled="!edit" form="formDialogEnvolvido" ng-obrigatorio="true"/>
  32 + ng-disabled="!edit" form="formDialogEnvolvido" ng-obrigatorio="true" />
33 33 </div>
34 34  
35 35 <div class="col-sm-3">
... ... @@ -38,10 +38,11 @@
38 38 ng-disabled="true" ng-obrigatorio="false"/>
39 39 </div><!-- .col-sm-4 -->
40 40  
41   - <div class="col-sm-3">
  41 + <div class="col-sm-3" >
42 42 <label-select ng-label="LABEL.PAPEL" ng-id="contratoEnvolvidoTemp.dominioPapelEnvolvidoContrato"
43 43 ng-model="contratoEnvolvidoTemp.dominioPapelEnvolvidoContrato" ng-list="dominioPapelEnvolvidoList"
44   - form="formDialogEnvolvido" ng-obrigatorio="editEnvolvido" ng-disabled="!editEnvolvido"
  44 + form="formDialogEnvolvido" ng-obrigatorio="editEnvolvido && dominioPapelEnvolvidoList.length > 0"
  45 + ng-disabled="!editEnvolvido || dominioPapelEnvolvidoList.length == 0"
45 46 ng-custom-options="dominioPapelEnvolvido.originalElement as dominioPapelEnvolvido.descricao for dominioPapelEnvolvido"
46 47 track-by="track by dominioPapelEnvolvido.id"/>
47 48 </div><!-- .col-sm-4 -->
... ... @@ -59,7 +60,7 @@
59 60 <div class="row">
60 61 <div class="col-sm-12">
61 62 <label-text-area ng-id="justificativaTemp.descricao" ng-label="LABEL.JUSTIFICATIVA" ng-hide="!editEnvolvido"
62   - form="formDialogJustificativa" ng-obrigatorio="contrato.id && hasAlteracaoEnvolvido" rows="3" ng-custom-maxlength="500"
  63 + form="formDialogJustificativa" rows="3" ng-custom-maxlength="500"
63 64 ng-model="justificativaTemp.descricao" ></label-text-area>
64 65 </div>
65 66 </div><!-- .row -->
... ...