Limpieza de modelos para buscador

This commit is contained in:
imnavajas
2024-02-21 13:44:23 +01:00
parent 26d2f32418
commit 88dca50aaf
4 changed files with 39 additions and 393 deletions

View File

@ -16,18 +16,19 @@ class BuscadorModel extends \App\Models\GoBaseModel
const SORTABLE = [
0 => "t1.id",
1 => "t1.created_at",
2 => "t2.nombre",
3 => "t3.first_name",
4 => "t1.titulo",
5 => "t5.nombre",
6 => "t1.inc_rei",
7 => "t1.paginas",
8 => "t1.tirada",
9 => "t1.total_presupuesto",
10 => "t6.estado",
2 => "t7.codigo",
3 => "t2.nombre",
4 => "t3.first_name",
5 => "t1.titulo",
6 => "t5.nombre",
7 => "t1.inc_rei",
8 => "t1.paginas",
9 => "t1.tirada",
10 => "t1.total_presupuesto",
11 => "t6.estado",
];
protected $allowedFields = [
/* protected $allowedFields = [
"cliente_id",
"user_created_id",
"user_update_id",
@ -99,48 +100,18 @@ class BuscadorModel extends \App\Models\GoBaseModel
"total_presupuesto",
"total_precio_unidad",
];
*/
protected $returnType = "App\Entities\Presupuestos\PresupuestoEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "titulo";
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
{
$sql =
"SELECT t1." .
$selcols .
", t2.nombre AS cliente, t3.nombre AS forma_pago, t4.nombre AS tipo_impresion, t5.nombre AS tipologia, t6.nombre AS pais, t7.estado AS estado, t8.id AS papel_formato, t9.first_name AS total_confirmado_user, t10.first_name AS aprobado_user FROM " .
$this->table .
" t1 LEFT JOIN clientes
t2 ON t1.cliente_id = t2.id LEFT JOIN lg_formas_pago
t3 ON t1.forma_pago_id = t3.id LEFT JOIN lg_tipos_impresion
t4 ON t1.tipo_impresion_id = t4.id LEFT JOIN lg_tipologias_libros
t5 ON t1.tipologia_id = t5.id LEFT JOIN lg_paises
t6 ON t1.pais_id = t6.id = t7.id LEFT JOIN presupuesto_estados
t7 ON t1.estado_id = t8.id LEFT JOIN lg_papel_formato
t8 ON t1.papel_formato_id = t9.id LEFT JOIN lg_papel_generico
t9 ON t1.total_confirmado_user_id = t26.id_user LEFT JOIN auth_user
t10 ON t1.aprobado_user_id = t27.id_user LEFT JOIN auth_user";
if (!is_null($limit) && intval($limit) > 0) {
$sql .= " LIMIT " . intval($limit);
}
if (!is_null($offset) && intval($offset) > 0) {
$sql .= " OFFSET " . intval($offset);
}
$query = $this->db->query($sql);
$result = $query->getResultObject();
return $result;
}
/**
* Get resource data.
@ -154,7 +125,7 @@ class BuscadorModel extends \App\Models\GoBaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.created_at AS fecha, t2.nombre AS cliente,
"t1.id AS id, t1.created_at AS fecha, t7.codigo as codigo, t2.nombre AS cliente,
CONCAT(t3.first_name, ' ', t3.last_name) AS comercial, t1.titulo AS titulo,
t5.nombre AS pais, t1.inc_rei AS inc_rei, t1.paginas AS paginas, t1.tirada AS tirada,
t1.total_presupuesto AS total_presupuesto, t1.total_presupuesto AS total_presupuesto,
@ -164,6 +135,7 @@ class BuscadorModel extends \App\Models\GoBaseModel
$builder->join("auth_user t3", "t1.user_update_id = t3.id_user", "left");
$builder->join("lg_paises t5", "t1.pais_id = t5.id", "left");
$builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left");
$builder->join("tipos_presupuestos t7", "t1.tipo_impresion_id = t7.id", "left");
$builder->where("t1.is_deleted", 0);