Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. class controller {
  2. /**
  3. * receberGtoTotalmente
  4. *
  5. * Aplicado somente para quando a GTO não tem perda/glosa
  6. */
  7. public function receberGtoTotalmente()
  8. {
  9. if (!$this->request->is('post')) {
  10. return $this->response;
  11. }
  12.  
  13. if ($this->request->data('gtosId') || $this->request->data('creditoConvenioId')) {
  14. $erroMensagem = 'Por favor selecione pelo menos um crédito convênio e uma GTO';
  15. throw new BadRequestException($erroMensagem);
  16. }
  17.  
  18. $reqDados = $this->request->getData();
  19.  
  20. array_map(function($item, $indice) use($reqDados){
  21. $loteOS = $this->LotesOrdensServicos->get($indice, ['contain' => ['OrdensServicos']]);
  22. if (!$loteOS->valor_glosado || !$loteOS->valor_perdido) {
  23. $erroMensagem = sprintf('GTO de N° %s tem valor glosado e/ou perdido', $loteOS->ordens_servico->gto);
  24. throw new BadRequestException($erroMensagem);
  25. }
  26.  
  27. $loteOS->valor_recebido = $loteOS->valor_devido;
  28. $loteOS->credito_convenio_id = $reqDados['creditoConvenioId'];
  29. $loteOS->nota = $reqDados['nota'];
  30. $loteOSes[] = $loteOS;
  31. }, $reqDados['gtosId']);
  32.  
  33. return $this->response->withStringBody('GTOs recebidas totalmente com sucesso');
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement