req->get("id", "")); $buscar = trim($this->req->get("q", "")); $herramienta = trim($this ->req->get("herramienta","")); $cantidad = trim($this ->req->get("cantidad","")); $inicio = trim($this->req->get("inicio", "")); $fin = trim($this->req->get("fin", "")); $query = $this->queryInicial; if($id > 0) { $query->andWhere(["id" => $id]); } if($herramienta){ $query->andWhere( ['idHerramienta'=>$herramienta]); } if($cantidad){ $query->andWhere( ['like', 'CAST(cantidad AS TEXT)', (string)$cantidad]); } if($buscar) { $query->andWhere([ "OR", ["ilike", "cantidad", $buscar] ]); } if ($inicio !== "" && $fin !== "") { $query->andWhere(['>=', '[[fechaIngreso]]', $inicio]) ->andWhere(['<=', '[[fechaIngreso]]', $fin]); } return new Respuesta($query, $this->limite, $this->pagina, $this->ordenar); } public function actionGuardar() { $id = trim($this->req->getBodyParam("id", "")); $modelo = null; if($id !== "") { $modelo = $this->modelClass::findOne($id); } if($modelo === null) { $modelo = new $this->modelClass(); $modelo->uuid(); $modelo->creado = new Expression('now()'); } else { $modelo->modificado = new Expression('now()'); } $modelo->load($this->req->getBodyParams(), ''); if (!$modelo->save()) { return (new Respuesta($modelo)) ->mensaje("Hubo un problema al guardar la herramienta en el inventario"); } $modelo->refresh(); return (new Respuesta($modelo)) ->mensaje("Herramienta en el inventario guardada"); } public function actionEliminar() { $id = trim($this->req->getBodyParam("id", "")); $modelo = null; if($id !== "") { $modelo = $this->modelClass::findOne(["id" => $id]); } if($modelo === null) { return (new Respuesta()) ->esError() ->mensaje("Herramienta en el inventario no encontrada"); } $modelo->eliminado = new Expression('now()'); if(!$modelo->save()) { return (new Respuesta($modelo)) ->mensaje("No se pudo eliminar herramienta del inventario"); } return (new Respuesta()) ->mensaje("Herramienta del inventario eliminada"); } }