|
@@ -31,6 +31,46 @@ class ObraHerramientaController extends AuthController {
|
|
|
|
|
|
return new Respuesta($query, $this->limite, $this->pagina, $this->ordenar);
|
|
|
}
|
|
|
+ public function actionGuardar()
|
|
|
+ {
|
|
|
+ $id = trim($this->req->getBodyParam("id", ""));
|
|
|
+ $modelo = null;
|
|
|
+ $nombre = $this->req->getBodyParam("idHerramienta", "");
|
|
|
+
|
|
|
+ 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(), '');
|
|
|
+
|
|
|
+ $registroExistente = $this->modelClass::find()
|
|
|
+ ->where(['idHerramienta' => $nombre])
|
|
|
+ ->andWhere(['!=', 'id', $id])
|
|
|
+ ->andWhere(['eliminado'=>null])// Excluir el registro actual en caso de edición
|
|
|
+ ->one();
|
|
|
+
|
|
|
+ if ($registroExistente !== null) {
|
|
|
+ return (new Respuesta($modelo))
|
|
|
+ ->esError()
|
|
|
+ ->mensaje("La Herramienta ya existe. Por favor, ingrese una Herramienta diferente.");
|
|
|
+ }
|
|
|
+ if (!$modelo->save()) {
|
|
|
+ return (new Respuesta($modelo))
|
|
|
+ ->mensaje("Hubo un problema al guardar el Gasto");
|
|
|
+ }
|
|
|
+
|
|
|
+ $modelo->refresh();
|
|
|
+ return (new Respuesta($modelo))
|
|
|
+ ->mensaje("Gasto guardado");
|
|
|
+ }
|
|
|
|
|
|
public function actionEliminar() {
|
|
|
$id = trim($this->req->getBodyParam("id", ""));
|