Browse Source

Se agrego controladores para obra herramienta y obra empleado

Jose Cienfuegos 8 months ago
parent
commit
69e313c435

+ 56 - 0
modules/v1/controllers/ObraEmpleadoController.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+
+class ObraEmpleadoController extends AuthController {
+
+  public $modelClass = "v1\models\ObraEmpleado";
+
+  public function actionIndex() {
+    $id = trim($this->req->get("id", ""));
+    $buscar = trim($this->req->get("q", ""));
+
+    $query = $this->queryInicial;
+
+    if($id > 0) {
+      $query->andWhere(["id" => $id]);
+    }
+
+    if($buscar) {
+      
+      $query->andWhere([
+        "OR",
+        ["ilike", "nombre", $buscar]
+      ]);
+
+    }
+
+    return new Respuesta($query, $this->limite, $this->pagina, $this->ordenar);
+  }
+
+  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("Empleado no encontrado");
+    }
+    $modelo->eliminado = new Expression('now()');
+    if(!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar el Empleado");
+    }
+
+    return (new Respuesta())
+      ->mensaje("Empleado eliminada");
+  }
+}

+ 56 - 0
modules/v1/controllers/ObraHerramientaController.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+
+class ObraHerramientaController extends AuthController {
+
+  public $modelClass = "v1\models\ObraHerramienta";
+
+  public function actionIndex() {
+    $id = trim($this->req->get("id", ""));
+    $buscar = trim($this->req->get("q", ""));
+
+    $query = $this->queryInicial;
+
+    if($id > 0) {
+      $query->andWhere(["id" => $id]);
+    }
+
+    if($buscar) {
+      
+      $query->andWhere([
+        "OR",
+        ["ilike", "nombre", $buscar]
+      ]);
+
+    }
+
+    return new Respuesta($query, $this->limite, $this->pagina, $this->ordenar);
+  }
+
+  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 no encontrada");
+    }
+    $modelo->eliminado = new Expression('now()');
+    if(!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar la Herramienta");
+    }
+
+    return (new Respuesta())
+      ->mensaje("Herramienta eliminada");
+  }
+}