public function cadastrar() { try { $id = trim($_POST['id']); $idcategoria = trim($_POST['categoria']); $idourives = trim($_POST['ourives']); $idproduto = trim($_POST['produto']); $servico = trim($_POST['titulo']); $idcliente = trim($_POST['cliente']); $valor = floatval(trim($_POST['valor'])); $dataprevistaentrega = trim($_POST['dataprevistaentrega']); $entregarpara = trim($_POST['entregarpara']); $observacao = trim($_POST['observacao']); $valorpago = floatval(trim($_POST['valorpago'])); $categoria = new CategoriaOS(); $categoria->id = $idcategoria; $categoria = $this->fachada->buscarCategoriaOS($categoria); $ourives = new Usuario(); $ourives->id = $idourives; $ourives = $this->fachada->buscarUsuario($ourives); $cliente = new Cliente(); $cliente->id = $idcliente; $cliente = $this->fachada->buscarCliente($cliente); $ordemServico = new OrdemServico(); $ordemServico->id = $id; if (!empty($ordemServico->id)) { $ordemServico = $this->fachada->buscarOrdemServico($ordemServico); } $ordemServico->categoria = $categoria; $ordemServico->ourives = $ourives; $ordemServico->observacao = $observacao; if (!empty($idproduto)) { $produto = new Produto(); $produto->id = $idproduto; $produto = $this->fachada->buscarProduto($produto); $ordemServico->produto = $produto; } $ordemServico->cliente = $cliente; $ordemServico->servico = $servico; $ordemServico->valor = $valor; $ordemServico->valorPago = $valorpago; $ordemServico->dataPrevistaEntrega = new \DateTime(Util::formartarDataBanco($dataprevistaentrega)); $ordemServico->entregarPara = $entregarpara; if (empty($ordemServico->id)) { $ordemServico->dataSolicitacao = new \DateTime("now"); $ordemServico->usuarioSolicitacao = $this->fachada->buscarUsuario($this->getUsuarioLogado()); $ordemServico->estado = OrdemServico::ABERTO; $this->fachada->inserirOrdemServico($ordemServico); } else { $ordemServico->dataAlteracao = new \DateTime("now"); $ordemServico->usuarioAlteracao = $this->fachada->buscarUsuario($this->getUsuarioLogado()); $this->fachada->atualizarOrdemServico($ordemServico); } echo new JSONResponse(true, self::MSG_OPERACAO_SUCESSO); } catch (\Exception $ex) { echo new JSONResponse(false, $ex->getMessage()); } }
public function buscarCliente() { try { if (empty($_POST['id'])) { throw new \InvalidArgumentException("Favor selecionar um cliente"); } $cliente = new Cliente(); $cliente->id = $_POST['id']; $cliente = $this->fachada->buscarCliente($cliente); echo new JSONResponse(true, $cliente); } catch (\Exception $e) { echo new JSONResponse(false, $e->getMessage()); } }