public function finalizarCompra() { try { $dataformat = new dataformat(); $this->load->library('dataValidator'); $dataValidator = new dataValidator(); $this->load->model('produtos/produtosModel'); $this->load->model('caixa/produtosVendidoModel'); $this->load->model('caixa/vendasModel'); $this->load->model('caixa/caixaAbertoModel'); $this->load->model('caixa/caixasModel'); $this->load->dao('caixa/caixasDao'); $formapagamento = $this->http->getRequest('formapagamento'); $valorrecebido = $dataformat->formatar($this->http->getRequest('valorrecebido'), 'decimal', 'banco'); if ($formapagamento == formapagamento::DINHEIRO) { $dataValidator->set('Valor recebido', $valorrecebido, 'valorrecebido')->is_required(); } //validando os dados de entrada if ($dataValidator->validate()) { $dataformat = new dataformat(); $caixa = unserialize($_SESSION['caixa']); $caixa->getCaixaAberto()[0]->getVendas()[0]->setDataVenda(date('Y-m-d')); $caixa->getCaixaAberto()[0]->getVendas()[0]->setHoraVenda(date('H:i:s')); //forma de pagamento escolhido if ($formapagamento == formapagamento::DINHEIRO) { $caixa->getCaixaAberto()[0]->getVendas()[0]->pagarComDinheiro(); } else { if ($formapagamento == formapagamento::CARTAOCREDITO) { $caixa->getCaixaAberto()[0]->getVendas()[0]->pagarComCartaoCredito(); } else { if ($formapagamento == formapagamento::CARTAODEBITO) { $caixa->getCaixaAberto()[0]->getVendas()[0]->pagarComCartaoDebito(); } } } //valor pago pelo cliente $caixa->getCaixaAberto()[0]->getVendas()[0]->setValorPago($valorrecebido); $caixasDao = new caixasDao(); if ($caixasDao->finalizarCompra($caixa)) { } $caixa->getCaixaAberto()[0]->setVendas(array(new vendasModel())); $_SESSION['caixa'] = serialize($caixa); $this->http->response(true); } else { $this->http->response('Informe o valor pago pelo cliente', 400); } } catch (Exception $e) { $this->http->response($e->getMessageError(), 400); } }