Commit b810adb2761fa80256a066c8c45c9baa6cb7ee33

Authored by Ronan Tavares Camargo
1 parent c63e6bc5
Exists in master

Redmine Atendimento #4999

cit-almoxarifado-api/src/main/java/br/com/centralit/api/model/AtendimentoRequisicaoConsumoItem.java
@@ -204,7 +204,8 @@ public class AtendimentoRequisicaoConsumoItem extends PersistentObjectAuditOrgan @@ -204,7 +204,8 @@ public class AtendimentoRequisicaoConsumoItem extends PersistentObjectAuditOrgan
204 204
205 public void setAtendimentoRequisicaoConsumoItemFIFOs( 205 public void setAtendimentoRequisicaoConsumoItemFIFOs(
206 Collection<AtendimentoRequisicaoConsumoItemFIFO> atendimentoRequisicaoConsumoItemFIFOs) { 206 Collection<AtendimentoRequisicaoConsumoItemFIFO> atendimentoRequisicaoConsumoItemFIFOs) {
207 - this.atendimentoRequisicaoConsumoItemFIFOs = atendimentoRequisicaoConsumoItemFIFOs; 207 + this.atendimentoRequisicaoConsumoItemFIFOs.clear();
  208 + this.atendimentoRequisicaoConsumoItemFIFOs.addAll(atendimentoRequisicaoConsumoItemFIFOs);
208 } 209 }
209 210
210 } 211 }
cit-almoxarifado-api/src/main/java/br/com/centralit/api/service/impl/AtendimentoRequisicaoConsumoServiceImpl.java
@@ -165,24 +165,27 @@ public class AtendimentoRequisicaoConsumoServiceImpl extends GenericServiceImpl&lt; @@ -165,24 +165,27 @@ public class AtendimentoRequisicaoConsumoServiceImpl extends GenericServiceImpl&lt;
165 165
166 if(atendimento.getId() == null && atendimento.getDataAtendimento() == null){ 166 if(atendimento.getId() == null && atendimento.getDataAtendimento() == null){
167 atendimento.setDataAtendimento(entity.getDataAtendimento()); 167 atendimento.setDataAtendimento(entity.getDataAtendimento());
  168 + this.montarEntidade(atendimento);
  169 +
  170 + this.validarDataAtendimento(atendimento);
  171 +
  172 + this.atualizarStatusRquisicao(atendimento);
  173 +
  174 + if(atendimento.getId() == null){
  175 + configurarNumeroAtendimento(atendimento);
  176 + }
  177 +
  178 + super.save(atendimento);
  179 +
  180 + this.movimentoEstoqueService.gerarMovimentoAtendimento(atendimento);
  181 +
  182 + this.requisicaoConsumoService.atualizarSituacaoAtendimento(atendimento.getRequisicaoConsumo().getId(), false);
  183 +
  184 + }else{
  185 + atendimento.setDataInativo(null);
  186 + atendimento.setDataAtendimento(entity.getDataAtendimento());
  187 + this.merge(atendimento);
168 } 188 }
169 -  
170 - this.montarEntidade(atendimento);  
171 -  
172 - this.validarDataAtendimento(atendimento);  
173 -  
174 - this.atualizarStatusRquisicao(atendimento);  
175 -  
176 - if(atendimento.getId() == null){  
177 - configurarNumeroAtendimento(atendimento);  
178 - }  
179 -  
180 - super.save(atendimento);  
181 -  
182 - this.movimentoEstoqueService.gerarMovimentoAtendimento(atendimento);  
183 -  
184 - this.requisicaoConsumoService.atualizarSituacaoAtendimento(atendimento.getRequisicaoConsumo().getId(), false);  
185 -  
186 } 189 }
187 190
188 } 191 }
@@ -246,40 +249,27 @@ public class AtendimentoRequisicaoConsumoServiceImpl extends GenericServiceImpl&lt; @@ -246,40 +249,27 @@ public class AtendimentoRequisicaoConsumoServiceImpl extends GenericServiceImpl&lt;
246 @Override 249 @Override
247 public AtendimentoRequisicaoConsumo merge(AtendimentoRequisicaoConsumo entity) { 250 public AtendimentoRequisicaoConsumo merge(AtendimentoRequisicaoConsumo entity) {
248 251
249 - if (this.movimentoEstoqueService.existeMovimentacaoDepois(entity, "atendimentoRequisicaoConsumoItem.atendimentoRequisicaoConsumo.id")) { 252 + if (this.movimentoEstoqueService.existeMovimentacaoDepois(entity, "idClasseReferencia")) {
250 253
251 throw new BusinessException(VALIDACAO_ERRO_EDICAO_EXISTE_MOVIMENTACAO, CodigoErro.REGRA_NEGOCIO.getValue()); 254 throw new BusinessException(VALIDACAO_ERRO_EDICAO_EXISTE_MOVIMENTACAO, CodigoErro.REGRA_NEGOCIO.getValue());
252 } 255 }
253 256
254 - if (!UtilColecao.isVazio(entity.getAtendimentos())) {  
255 -  
256 - for (AtendimentoRequisicaoConsumo atendimento : entity.getAtendimentos()) {  
257 -  
258 - removerLancamentosPassados(atendimento);  
259 -  
260 - this.montarEntidade(atendimento); 257 + removerLancamentosPassados(entity);
261 258
262 - this.validarDataAtendimento(atendimento); 259 + this.montarEntidade(entity);
  260 +
  261 + this.validarDataAtendimento(entity);
263 262
264 - this.atualizarStatusRquisicao(atendimento); 263 + this.atualizarStatusRquisicao(entity);
265 264
266 - AtendimentoRequisicaoConsumo atendimentoRequisicaoConsumo = super.merge(atendimento); 265 + super.merge(entity);
267 266
268 - //Apaga movimentos de estoque  
269 - this.movimentoEstoqueService.removerMovimentosAtendimento(atendimentoRequisicaoConsumo); 267 + this.movimentoEstoqueService.gerarMovimentoAtendimento(entity);
270 268
271 - //Apaga movimentos contabeis  
272 - for (AtendimentoRequisicaoConsumoItem atendimentoItem : atendimento.getAtendimentoRequisicaoConsumoItems()){  
273 - this.contaContabilMovimentoService.removerMovimentosAtendimento(atendimentoItem.getId());  
274 - }  
275 - this.movimentoEstoqueService.gerarMovimentoAtendimento(atendimentoRequisicaoConsumo);  
276 -  
277 - this.requisicaoConsumoService.atualizarSituacaoAtendimento(atendimento.getRequisicaoConsumo().getId(), false);  
278 - } 269 + this.requisicaoConsumoService.atualizarSituacaoAtendimento(entity.getRequisicaoConsumo().getId(), false);
279 270
280 - }  
281 271
282 - return new AtendimentoRequisicaoConsumo(); 272 + return entity;
283 273
284 } 274 }
285 275
@@ -307,6 +297,7 @@ public class AtendimentoRequisicaoConsumoServiceImpl extends GenericServiceImpl&lt; @@ -307,6 +297,7 @@ public class AtendimentoRequisicaoConsumoServiceImpl extends GenericServiceImpl&lt;
307 for (MovimentoEstoque movimentoEstoque : movimentosEstoque) { 297 for (MovimentoEstoque movimentoEstoque : movimentosEstoque) {
308 this.movimentoEstoqueService.remove(movimentoEstoque); 298 this.movimentoEstoqueService.remove(movimentoEstoque);
309 } 299 }
  300 +
310 } 301 }
311 } 302 }
312 303
cit-almoxarifado-api/src/main/java/br/com/centralit/api/service/impl/MovimentoEstoqueServiceImpl.java
@@ -542,7 +542,10 @@ public class MovimentoEstoqueServiceImpl extends GenericServiceImpl&lt;MovimentoEst @@ -542,7 +542,10 @@ public class MovimentoEstoqueServiceImpl extends GenericServiceImpl&lt;MovimentoEst
542 542
543 MovimentoEstoque ultimoMovimentoAtendimento = this.movimentoEstoqueDao.ultimoMovimento(entity, joinClass); 543 MovimentoEstoque ultimoMovimentoAtendimento = this.movimentoEstoqueDao.ultimoMovimento(entity, joinClass);
544 544
545 - return this.movimentoEstoqueDao.existeMovimentacaoDepoisDoMovimento(ultimoMovimentoAtendimento, usuarioLogado.getOrganizacao()); 545 + if(ultimoMovimentoAtendimento != null){
  546 + return this.movimentoEstoqueDao.existeMovimentacaoDepoisDoMovimento(ultimoMovimentoAtendimento, usuarioLogado.getOrganizacao());
  547 + }
  548 + return false;
546 } 549 }
547 550
548 /** 551 /**
cit-almoxarifado-api/src/main/java/br/com/centralit/api/service/validation/AtendimentoRequisicaoConsumoItemValidator.java
@@ -22,7 +22,7 @@ public class AtendimentoRequisicaoConsumoItemValidator implements Validator { @@ -22,7 +22,7 @@ public class AtendimentoRequisicaoConsumoItemValidator implements Validator {
22 22
23 ValidationUtils.rejectIfEmpty(errors, "atendimentoRequisicaoConsumo", CodigoErro.VALIDACAO_CAMPOS_OBRIGATORIOS.getValue().toString(), "LABEL.ATENDIMENTOREQUISICAOCONSUMO"); 23 ValidationUtils.rejectIfEmpty(errors, "atendimentoRequisicaoConsumo", CodigoErro.VALIDACAO_CAMPOS_OBRIGATORIOS.getValue().toString(), "LABEL.ATENDIMENTOREQUISICAOCONSUMO");
24 24
25 - ValidationUtils.rejectIfEmpty(errors, "materialConsumo", CodigoErro.VALIDACAO_CAMPOS_OBRIGATORIOS.getValue().toString(), "LABEL.MATERIALCONSUMO"); 25 + ValidationUtils.rejectIfEmpty(errors, "material", CodigoErro.VALIDACAO_CAMPOS_OBRIGATORIOS.getValue().toString(), "LABEL.MATERIALCONSUMO");
26 26
27 ValidationUtils.rejectIfEmpty(errors, "quantidade", CodigoErro.VALIDACAO_CAMPOS_OBRIGATORIOS.getValue().toString(), "ALMOXARIFADO.LABEL.QUANTIDADE"); 27 ValidationUtils.rejectIfEmpty(errors, "quantidade", CodigoErro.VALIDACAO_CAMPOS_OBRIGATORIOS.getValue().toString(), "ALMOXARIFADO.LABEL.QUANTIDADE");
28 28