Просмотр исходного кода

Merge branch 'master' of git.miralo.xyz:SAGARHPA/Sagarhpa_2024_api_php

Isaac Noriega месяцев назад: 9
Родитель
Сommit
9b01c965c8

+ 27 - 0
migrations/m240626_181104_columna_idSagarhpa_en_catalogos.php

@@ -0,0 +1,27 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240626_181104_columna_idSagarhpa_en_catalogos
+ */
+class m240626_181104_columna_idSagarhpa_en_catalogos extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->addColumn('Estado', 'idSagarhpa', $this->integer());
+        $this->addColumn('Municipio', 'idSagarhpa', $this->integer());
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropColumn('Municipio', 'idSagarhpa', $this->integer());
+        $this->dropColumn('Estado', 'idSagarhpa', $this->integer());
+    }
+}

+ 5 - 3
models/Estado.php

@@ -31,9 +31,10 @@ class Estado extends ModeloBase {
   public function rules() {
     return [
       [['id'], 'required'],
-      [['clave'], 'integer'],
+      /* [['clave'], 'integer'], */
       [['creado', 'modificado', 'eliminado'], 'safe'],
       [['id', 'pais'], 'string', 'max' => 36],
+      [['idSagarhpa'], 'integer'],
       [['nombre'], 'string', 'max' => 100],
       [['abreviacion'], 'string', 'max' => 16],
       [['id'], 'unique'],
@@ -46,13 +47,14 @@ class Estado extends ModeloBase {
   public function attributeLabels() {
     return [
       'id' => 'ID',
+      'idSagarhpa' => 'ID Sagarhpa',
       'nombre' => 'Nombre',
       'abreviacion' => 'Abreviacion',
       'creado' => 'Creado',
       'modificado' => 'Modificado',
       'eliminado' => 'Eliminado',
-      'clave' => 'Clave',
-      'pais' => 'Pais',
+      /* 'clave' => 'Clave', */
+     /*  'pais' => 'Pais', */
     ];
   }
 

+ 3 - 1
models/Municipio.php

@@ -35,6 +35,7 @@ class Municipio extends ModeloBase {
       [['id', 'idEstado'], 'string', 'max' => 36],
       [['nombre'], 'string', 'max' => 100],
       [['id'], 'unique'],
+      [['idSagarhpa'], 'integer'],
       [['idEstado'], 'exist', 'skipOnError' => true, 'targetClass' => Estado::class, 'targetAttribute' => ['idEstado' => 'id']],
     ];
   }
@@ -45,12 +46,13 @@ class Municipio extends ModeloBase {
   public function attributeLabels() {
     return [
       'id' => 'ID',
+      'idSagarhpa' => 'ID Sagarhpa',
       'nombre' => 'Nombre',
       'idEstado' => 'Id Estado',
       'creado' => 'Creado',
       'modificado' => 'Modificado',
       'eliminado' => 'Eliminado',
-      'clave' => 'Clave'
+      /* 'clave' => 'Clave' */
     ];
   }
 

+ 2 - 1
modules/v1/controllers/EstadoController.php

@@ -23,7 +23,8 @@ class EstadoController extends AuthController {
     if (!empty($buscar)) {
       $query->andWhere([
         'or',
-        ['ilike', 'nombre', $buscar],
+        ['ilike', '[[Estado]].{{nombre}}', $buscar],
+        ['ilike', '[[Estado]].{{abreviacion}}', $buscar],
       ]);
     }
     

+ 8 - 9
modules/v1/controllers/MunicipioController.php

@@ -22,20 +22,19 @@ class MunicipioController extends AuthController {
     $query = $this->queryInicial->joinWith(['estado']);
 
     if ($idEstado !== "") {
-      $query->andWhere(["Estado.id" => $idEstado]);
+      $query->andWhere(["[[Estado]].{{id}}" => $idEstado]);
     }
 
     if ($id !== "") {
-      $query->andWhere(["Municipio.id" => $id]);
+      $query->andWhere(["[[Municipio]].{{id}}" => $id]);
     }
 
-    if (!empty($buscar)) {
-      $query->andWhere([
-        'or',
-        ['ilike', 'Municipio.nombre', $buscar],
-        ['ilike', 'Estado.nombre', $buscar],
-      ]);
-    }
+    $query->andWhere([
+      "OR",
+      "f_unaccent({{Municipio}}.[[nombre]]) ilike f_unaccent(:q)",
+      "f_unaccent({{Estado}}.[[nombre]]) ilike f_unaccent(:q)",
+    ])->addParams([':q' => "%{$buscar}%"]);
+    //
 
     return new Respuesta($query, $this->limite, $this->pagina, $this->ordenar);
   }

+ 5 - 6
modules/v1/controllers/ProductoController.php

@@ -26,12 +26,11 @@ class ProductoController extends AuthController {
       $query->andWhere(["idPadre" => $idPadre]);
     }
 
-    if (!empty($buscar)) {
-      if (is_numeric($buscar)) {
-        $query->andWhere(['idSagarhpa' => $buscar]);
-      } else {
-        $query->andWhere(['ilike', 'nombre', $buscar]);
-      }
+    if($buscar) {
+      $query->andWhere([
+        "OR",
+        ["ilike", "[[Producto]].{{nombre}}", $buscar],
+      ]);
     }
 
     if ($padre) {

+ 1 - 2
modules/v1/models/Estado.php

@@ -7,12 +7,11 @@ class Estado extends \app\models\Estado {
   public function fields() {
     return [
       "id",
+      'idSagarhpa',
       "nombre",
       "abreviacion",
       "creado",
       "modificado",
-      "clave",
-      "pais"
     ];
   }
 

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

@@ -7,6 +7,7 @@ class Municipio extends \app\models\Municipio {
   public function fields() {
     return [
       'id',
+      'idSagarhpa',
       'nombre',
       'idEstado',
       'creado',