瀏覽代碼

Catalogos

OscarGil03 1 年之前
父節點
當前提交
f1903c146d

+ 63 - 0
migrations/m240515_224734_estado_municipio.php

@@ -0,0 +1,63 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240515_224734_estado_municipio
+ */
+class m240515_224734_estado_municipio extends Migration {
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp() {
+        $this->createTable("Estado", [
+            "id" => $this->string(36),
+            "nombre" => $this->string(100),
+            "abreviacion" => $this->string(16),
+            "creado" => $this->timestamp(),
+            "modificado" => $this->timestamp(),
+            "eliminado" => $this->timestamp(),
+        ]);
+
+        $this->addPrimaryKey("EstadoPK", "Estado", "id");
+
+        $this->createTable("Municipio", [
+            "id" => $this->string(36),
+            "nombre" => $this->string(100),
+            "idEstado" => $this->string(36),
+            "creado" => $this->timestamp(),
+            "modificado" => $this->timestamp(),
+            "eliminado" => $this->timestamp(),
+        ]);
+
+        $this->addPrimaryKey("MunicipioPK", "Municipio", "id");
+        $this->addForeignKey("MunicipioEstadoIdFK", "Municipio", "idEstado", "Estado", "id");
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown() {
+        $this->dropForeignKey("MunicipioEstadoIdFK", "Municipio");
+        $this->dropPrimaryKey("EstadoPK", "Estado");
+        $this->dropPrimaryKey("MunicipioPK", "Municipio");
+
+        $this->dropTable("Municipio");
+        $this->dropTable("Estado");
+    }
+
+    /*
+    // Use up()/down() to run migration code without a transaction.
+    public function up()
+    {
+
+    }
+
+    public function down()
+    {
+        echo "m240515_224734_estado_municipio cannot be reverted.\n";
+
+        return false;
+    }
+    */
+}

+ 61 - 0
migrations/m240516_235323_fin_tipo_movilizacion.php

@@ -0,0 +1,61 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240516_235323_fin_tipo_movilizacion
+ */
+class m240516_235323_fin_tipo_movilizacion extends Migration {
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp() {
+        $this->createTable("FinMovilizacion", [
+            "id" => $this->string(36),
+            "nombre" => $this->string(100),
+            "idSagarhpa" => $this->integer(),
+            "creado" => $this->timestamp(),
+            "modificado" => $this->timestamp(),
+            "eliminado" => $this->timestamp(),
+        ]);
+
+        $this->addPrimaryKey("FinMovilizacionPK", "FinMovilizacion", "id");
+
+        $this->createTable("TipoMovilizacion", [
+            "id" => $this->string(36),
+            "nombre" => $this->string(100),
+            "idSagarhpa" => $this->integer(),
+            "creado" => $this->timestamp(),
+            "modificado" => $this->timestamp(),
+            "eliminado" => $this->timestamp(),
+        ]);
+
+        $this->addPrimaryKey("TipoMovilizacionPK", "TipoMovilizacion", "id");
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown() {
+        $this->dropPrimaryKey("FinMovilizacionPK", "FinMovilizacion");
+        $this->dropPrimaryKey("TipoMovilizacionPK", "TipoMovilizacion");
+
+        $this->dropTable("FinMovilizacion");
+        $this->dropTable("TipoMovilizacion");
+    }
+
+    /*
+    // Use up()/down() to run migration code without a transaction.
+    public function up()
+    {
+
+    }
+
+    public function down()
+    {
+        echo "m240516_235323_fin_tipo_movilizacion cannot be reverted.\n";
+
+        return false;
+    }
+    */
+}

+ 69 - 0
models/Estado.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+use yii\base\Model;
+
+/**
+ * This is the model class for table "Estado".
+ *
+ * @property string $id
+ * @property string|null $nombre
+ * @property string|null $abreviacion
+ * @property string|null $creado
+ * @property string|null $modificado
+ * @property string|null $eliminado
+ *
+ * @property Municipio[] $municipios
+ */
+class Estado extends ModeloBase
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'Estado';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id'], 'required'],
+            [['creado', 'modificado', 'eliminado'], 'safe'],
+            [['id'], 'string', 'max' => 36],
+            [['nombre'], 'string', 'max' => 100],
+            [['abreviacion'], 'string', 'max' => 16],
+            [['id'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'nombre' => 'Nombre',
+            'abreviacion' => 'Abreviacion',
+            'creado' => 'Creado',
+            'modificado' => 'Modificado',
+            'eliminado' => 'Eliminado',
+        ];
+    }
+
+    /**
+     * Gets query for [[Municipios]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getMunicipios()
+    {
+        return $this->hasMany(Municipio::class, ['idEstado' => 'id']);
+    }
+}

+ 57 - 0
models/FinMovilizacion.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "FinMovilizacion".
+ *
+ * @property string $id
+ * @property string|null $nombre
+ * @property int|null $idSagarhpa
+ * @property string|null $creado
+ * @property string|null $modificado
+ * @property string|null $eliminado
+ */
+class FinMovilizacion extends ModeloBase
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'FinMovilizacion';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id'], 'required'],
+            [['idSagarhpa'], 'default', 'value' => null],
+            [['idSagarhpa'], 'integer'],
+            [['creado', 'modificado', 'eliminado'], 'safe'],
+            [['id'], 'string', 'max' => 36],
+            [['nombre'], 'string', 'max' => 100],
+            [['id'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'nombre' => 'Nombre',
+            'idSagarhpa' => 'Id Sagarhpa',
+            'creado' => 'Creado',
+            'modificado' => 'Modificado',
+            'eliminado' => 'Eliminado',
+        ];
+    }
+}

+ 68 - 0
models/Municipio.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "Municipio".
+ *
+ * @property string $id
+ * @property string|null $nombre
+ * @property string|null $idEstado
+ * @property string|null $creado
+ * @property string|null $modificado
+ * @property string|null $eliminado
+ *
+ * @property Estado $idEstado
+ */
+class Municipio extends ModeloBase
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'Municipio';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id'], 'required'],
+            [['creado', 'modificado', 'eliminado'], 'safe'],
+            [['id', 'idEstado'], 'string', 'max' => 36],
+            [['nombre'], 'string', 'max' => 100],
+            [['id'], 'unique'],
+            [['idEstado'], 'exist', 'skipOnError' => true, 'targetClass' => Estado::class, 'targetAttribute' => ['idEstado' => 'id']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'nombre' => 'Nombre',
+            'idEstado' => 'Id Estado',
+            'creado' => 'Creado',
+            'modificado' => 'Modificado',
+            'eliminado' => 'Eliminado',
+        ];
+    }
+
+    /**
+     * Gets query for [[IdEstado]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getIdEstado()
+    {
+        return $this->hasOne(Estado::class, ['id' => 'idEstado']);
+    }
+}

+ 57 - 0
models/TipoMovilizacion.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "TipoMovilizacion".
+ *
+ * @property string $id
+ * @property string|null $nombre
+ * @property int|null $idSagarhpa
+ * @property string|null $creado
+ * @property string|null $modificado
+ * @property string|null $eliminado
+ */
+class TipoMovilizacion extends ModeloBase
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'TipoMovilizacion';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id'], 'required'],
+            [['idSagarhpa'], 'default', 'value' => null],
+            [['idSagarhpa'], 'integer'],
+            [['creado', 'modificado', 'eliminado'], 'safe'],
+            [['id'], 'string', 'max' => 36],
+            [['nombre'], 'string', 'max' => 100],
+            [['id'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'nombre' => 'Nombre',
+            'idSagarhpa' => 'Id Sagarhpa',
+            'creado' => 'Creado',
+            'modificado' => 'Modificado',
+            'eliminado' => 'Eliminado',
+        ];
+    }
+}

+ 94 - 0
modules/v1/controllers/EstadoController.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+
+class EstadoController extends AuthController {
+
+  public $modelClass = "v1\models\Estado";
+
+  public function actionIndex() {
+    $id = trim($this->req->get("id", ""));
+    $buscar = trim($this->req->get("q", ""));
+
+    $query = $this->queryInicial;
+
+    if ($id !== "") {
+      $query->andWhere(["id" => $id]);
+    }
+
+    if ($buscar) {
+      $query->andWhere([
+        "OR",
+        "f_unaccent([[nombre]]) ilike f_unaccent(:q)",
+      ])->addParams([':q' => "%{$buscar}%"]);
+    }
+
+    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);
+    }
+
+    $tran = \Yii::$app->getDb()->beginTransaction();
+    try {
+      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))
+          ->esError()
+          ->mensaje("Hubo un problema al guardar el registro del Estado.");
+      }
+
+      $tran->commit();
+      $modelo->refresh();
+
+      return (new Respuesta($modelo))
+        ->mensaje("Registro de Estado guardado con éxito.");
+
+    } catch (\Exception $e) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Hubo un error en el servidor" . $e->getMessage());
+    }
+  }
+
+  public function actionEliminar() {
+    $id = trim($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if ($id !== "") {
+      $modelo = $this->modelClass::findOne(["id" => $id]);
+    }
+    if ($modelo === null) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Registro de Estado no encontrado.");
+    }
+
+    $modelo->eliminado = new Expression('now()');
+    if (!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar el registro del Estado.");
+    }
+
+    return (new Respuesta())
+      ->mensaje("Registro de Estado eliminado.");
+  }
+}

+ 94 - 0
modules/v1/controllers/FinMovilizacionController.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+
+class FinMovilizacionController extends AuthController {
+
+  public $modelClass = "v1\models\FinMovilizacion";
+
+  public function actionIndex() {
+    $id = trim($this->req->get("id", ""));
+    $buscar = trim($this->req->get("q", ""));
+
+    $query = $this->queryInicial;
+
+    if ($id !== "") {
+      $query->andWhere(["id" => $id]);
+    }
+
+    if ($buscar) {
+      $query->andWhere([
+        "OR",
+        "f_unaccent([[nombre]]) ilike f_unaccent(:q)",
+      ])->addParams([':q' => "%{$buscar}%"]);
+    }
+
+    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);
+    }
+
+    $tran = \Yii::$app->getDb()->beginTransaction();
+    try {
+      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))
+          ->esError()
+          ->mensaje("Hubo un problema al guardar el registro de Fin de Movilizacion.");
+      }
+
+      $tran->commit();
+      $modelo->refresh();
+
+      return (new Respuesta($modelo))
+        ->mensaje("Registro de Fin de Movilizacion guardado con éxito.");
+
+    } catch (\Exception $e) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Hubo un error en el servidor" . $e->getMessage());
+    }
+  }
+
+  public function actionEliminar() {
+    $id = trim($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if ($id !== "") {
+      $modelo = $this->modelClass::findOne(["id" => $id]);
+    }
+    if ($modelo === null) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Registro de Fin de Movilizacion no encontrado.");
+    }
+
+    $modelo->eliminado = new Expression('now()');
+    if (!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar el registro del Fin de Movilizacion.");
+    }
+
+    return (new Respuesta())
+      ->mensaje("Registro de Fin de Movilizacion eliminado.");
+  }
+}

+ 102 - 0
modules/v1/controllers/MunicipioController.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+use app\models\Municipio;
+
+class MunicipioController extends AuthController {
+
+  public $modelClass = "v1\models\Municipio";
+
+  public function actionIndex() {
+    $id = trim($this->req->get("id", ""));
+    $buscar = trim($this->req->get("q", ""));
+    $idEstado = trim($this->req->get("idEstado", ""));
+
+
+    $query = $this->queryInicial->joinWith(['estado']);
+
+    if ($idEstado !== "") {
+      $query->andWhere(["Estado.id" => $idEstado]);
+  }
+
+  if ($id !== "") {
+      $query->andWhere(["Municipio.id" => $id]);
+  }
+
+    if (!empty($buscar)) {
+      $query->andWhere([
+        'or',
+        ['ilike', 'Municipio.nombre', $buscar],
+        ['ilike', 'Estado.nombre', $buscar],
+      ]);
+    }
+
+    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);
+    }
+
+    $tran = \Yii::$app->getDb()->beginTransaction();
+    try {
+      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))
+          ->esError()
+          ->mensaje("Hubo un problema al guardar el registro del Municipio.");
+      }
+
+      $tran->commit();
+      $modelo->refresh();
+
+      return (new Respuesta($modelo))
+        ->mensaje("Registro de Municipio guardado con éxito.");
+
+    } catch (\Exception $e) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Hubo un error en el servidor" . $e->getMessage());
+    }
+  }
+
+  public function actionEliminar() {
+    $id = trim($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if ($id !== "") {
+      $modelo = $this->modelClass::findOne(["id" => $id]);
+    }
+    if ($modelo === null) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Registro de Municipio no encontrado.");
+    }
+
+    $modelo->eliminado = new Expression('now()');
+    if (!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar el registro del Municipio.");
+    }
+
+    return (new Respuesta())
+      ->mensaje("Registro de Municipio eliminado.");
+  }
+}

+ 94 - 0
modules/v1/controllers/TipoMovilizacionController.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+
+class TipoMovilizacionController extends AuthController {
+
+  public $modelClass = "v1\models\TipoMovilizacion";
+
+  public function actionIndex() {
+    $id = trim($this->req->get("id", ""));
+    $buscar = trim($this->req->get("q", ""));
+
+    $query = $this->queryInicial;
+
+    if ($id !== "") {
+      $query->andWhere(["id" => $id]);
+    }
+
+    if ($buscar) {
+      $query->andWhere([
+        "OR",
+        "f_unaccent([[nombre]]) ilike f_unaccent(:q)",
+      ])->addParams([':q' => "%{$buscar}%"]);
+    }
+
+    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);
+    }
+
+    $tran = \Yii::$app->getDb()->beginTransaction();
+    try {
+      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))
+          ->esError()
+          ->mensaje("Hubo un problema al guardar el registro de Tipo de Movilizacion.");
+      }
+
+      $tran->commit();
+      $modelo->refresh();
+
+      return (new Respuesta($modelo))
+        ->mensaje("Registro de Tipo de Movilizacion guardado con éxito.");
+
+    } catch (\Exception $e) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Hubo un error en el servidor" . $e->getMessage());
+    }
+  }
+
+  public function actionEliminar() {
+    $id = trim($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if ($id !== "") {
+      $modelo = $this->modelClass::findOne(["id" => $id]);
+    }
+    if ($modelo === null) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("Registro de Tipo de Movilizacion no encontrado.");
+    }
+
+    $modelo->eliminado = new Expression('now()');
+    if (!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar el registro del Tipo de Movilizacion.");
+    }
+
+    return (new Respuesta())
+      ->mensaje("Registro de Tipo de Movilizacion eliminado.");
+  }
+}

+ 23 - 0
modules/v1/models/Estado.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace v1\models;
+
+class Estado extends \app\models\Estado
+{
+
+  public function fields()
+  {
+    return [
+      "id",
+      "nombre",
+      "abreviacion",
+      "creado",
+      "modificado"
+    ];
+  }
+
+  public function getMunicipios()
+  {
+    return $this->hasMany(Municipio::className(), ['idEstado' => 'idEstado'])->andWhere(["eliminado" => null]);
+  }
+}

+ 18 - 0
modules/v1/models/FinMovilizacion.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace v1\models;
+
+class FinMovilizacion extends \app\models\FinMovilizacion
+{
+
+  public function fields()
+  {
+    return [
+      "id",
+      "nombre",
+      "idSagarhpa",
+      "creado",
+      "modificado"
+    ];
+  }
+}

+ 26 - 0
modules/v1/models/Municipio.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace v1\models;
+
+class Municipio extends \app\models\Municipio {
+
+  public function fields() {
+    return [
+      'id',
+      'nombre',
+      'idEstado',
+      'creado',
+      'modificado'
+    ];
+  }
+
+  public function extraFields() {
+    return [
+      'estado'
+    ];
+  }
+
+  public function getEstado() {
+    return $this->hasOne(Estado::class, ['id' => 'idEstado']);
+  }
+}

+ 18 - 0
modules/v1/models/TipoMovilizacion.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace v1\models;
+
+class TipoMovilizacion extends \app\models\TipoMovilizacion
+{
+
+  public function fields()
+  {
+    return [
+      "id",
+      "nombre",
+      "idSagarhpa",
+      "creado",
+      "modificado"
+    ];
+  }
+}