Last active
September 6, 2019 18:34
-
-
Save lpj145/8c54b813b34081b1b7cef44696477d39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class controller { | |
| /** | |
| * receberGtoTotalmente | |
| * | |
| * Aplicado somente para quando a GTO não tem perda/glosa | |
| */ | |
| public function receberGtoTotalmente() | |
| { | |
| if (!$this->request->is('post')) { | |
| return $this->response; | |
| } | |
| if ($this->request->data('gtosId') || $this->request->data('creditoConvenioId')) { | |
| $erroMensagem = 'Por favor selecione pelo menos um crédito convênio e uma GTO'; | |
| throw new BadRequestException($erroMensagem); | |
| } | |
| $reqDados = $this->request->getData(); | |
| array_map(function($item, $indice) use($reqDados){ | |
| $loteOS = $this->LotesOrdensServicos->get($indice, ['contain' => ['OrdensServicos']]); | |
| if (!$loteOS->valor_glosado || !$loteOS->valor_perdido) { | |
| $erroMensagem = sprintf('GTO de N° %s tem valor glosado e/ou perdido', $loteOS->ordens_servico->gto); | |
| throw new BadRequestException($erroMensagem); | |
| } | |
| $loteOS->valor_recebido = $loteOS->valor_devido; | |
| $loteOS->credito_convenio_id = $reqDados['creditoConvenioId']; | |
| $loteOS->nota = $reqDados['nota']; | |
| $loteOSes[] = $loteOS; | |
| }, $reqDados['gtosId']); | |
| return $this->response->withStringBody('GTOs recebidas totalmente com sucesso'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment