mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
datos envio clientes
This commit is contained in:
118
ci4/app/Models/Clientes/ClienteDireccionesModel.php
Normal file
118
ci4/app/Models/Clientes/ClienteDireccionesModel.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Clientes;
|
||||
|
||||
class ClienteDireccionesModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "cliente_direcciones";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
0 => "t1.att",
|
||||
1 => "t1.email",
|
||||
2 => "t1.direccion",
|
||||
3 => "t1.cp",
|
||||
4 => "t5.municipio_nombre",
|
||||
5 => "t4.nombre",
|
||||
6 => "t3.nombre",
|
||||
7 => "t1.telefono",
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
"cliente_id",
|
||||
"att",
|
||||
"email",
|
||||
"direccion",
|
||||
"pais_id",
|
||||
"ccaa_id",
|
||||
"provincia_id",
|
||||
"municipio_id",
|
||||
"cp",
|
||||
"telefono",
|
||||
];
|
||||
|
||||
protected $returnType = "App\Entities\Clientes\ClienteDireccionesEntity";
|
||||
|
||||
public static $labelField = "id";
|
||||
|
||||
protected $validationRules = [
|
||||
"att" => [
|
||||
"label" => "ClienteDirecciones.att",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
"email" => [
|
||||
"label" => "ClienteDirecciones.email",
|
||||
"rules" => "trim|max_length[100]|valid_email",
|
||||
],
|
||||
"cp" => [
|
||||
"label" => "ClienteDirecciones.cp",
|
||||
"rules" => "trim|max_length[20]",
|
||||
],
|
||||
"telefono" => [
|
||||
"label" => "ClienteDirecciones.telefono",
|
||||
"rules" => "trim|max_length[40]",
|
||||
],
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
"att" => [
|
||||
"max_length" => "ClienteDirecciones.validation.max_length",
|
||||
],
|
||||
"email" => [
|
||||
"max_length" => "ClienteDirecciones.validation.max_length",
|
||||
],
|
||||
"cp" => [
|
||||
"max_length" => "ClienteDirecciones.validation.max_length",
|
||||
"valid_email" => "ClienteDirecciones.validation.valid_email",
|
||||
],
|
||||
"telefono" => [
|
||||
"max_length" => "ClienteDirecciones.validation.max_length",
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "", $cliente_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.cliente_id AS cliente_id, t2.nombre as cliente_nombre, t1.att AS att,
|
||||
t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t3.nombre AS pais,
|
||||
t1.ccaa_id AS ccaa_id, t4.nombre AS ccaa_nombre,
|
||||
t1.municipio_id AS municipio_id, t5.municipio_nombre AS municipio_nombre, t1.cp AS cp, t1.telefono AS telefono"
|
||||
);
|
||||
|
||||
$builder->where('t1.cliente_id', $cliente_id);
|
||||
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
|
||||
$builder->join("lg_paises t3", "t1.pais_id = t3.id", "left");
|
||||
$builder->join("lg_comunidades_autonomas t4", "t1.ccaa_id = t4.id", "left");
|
||||
$builder->join("municipios t5", "t1.municipio_id = t5.id", "left");
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.att", $search)
|
||||
->orLike("t1.email", $search)
|
||||
->orLike("t1.direccion", $search)
|
||||
->orLike("t3.nombre", $search)
|
||||
->orLike("t4.nombre", $search)
|
||||
->orLike("t5.municipio_nombre", $search)
|
||||
->orLike("t1.cp", $search)
|
||||
->orLike("t1.telefono", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user