mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
204 lines
6.7 KiB
PHP
204 lines
6.7 KiB
PHP
<?php
|
|
namespace App\Models\compras;
|
|
|
|
class ProveedorModel extends \App\Models\GoBaseModel
|
|
{
|
|
protected $table = "lg_proveedores";
|
|
|
|
/**
|
|
* Whether primary key uses auto increment.
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $useAutoIncrement = true;
|
|
|
|
const SORTABLE = [
|
|
1 => "t1.id",
|
|
2 => "t1.nombre",
|
|
3 => "t1.tipo_id",
|
|
4 => "t1.razon_social",
|
|
5 => "t1.cif",
|
|
6 => "t1.direccion",
|
|
7 => "t1.cp",
|
|
8 => "t1.ciudad",
|
|
9 => "t1.provincia_id",
|
|
10 => "t1.pais_id",
|
|
11 => "t1.persona_contacto",
|
|
12 => "t1.email",
|
|
13 => "t1.telefono",
|
|
14 => "t2.nombre",
|
|
15 => "t3.nombre",
|
|
16 => "t4.nombre",
|
|
];
|
|
|
|
protected $allowedFields = [
|
|
"nombre",
|
|
"tipo_id",
|
|
"razon_social",
|
|
"cif",
|
|
"direccion",
|
|
"cp",
|
|
"ciudad",
|
|
"provincia_id",
|
|
"pais_id",
|
|
"persona_contacto",
|
|
"email",
|
|
"telefono",
|
|
];
|
|
protected $returnType = "App\Entities\compras\ProveedorEntity";
|
|
|
|
protected $useTimestamps = true;
|
|
protected $useSoftDeletes = false;
|
|
|
|
protected $createdField = "created_at";
|
|
|
|
protected $updatedField = "updated_at";
|
|
|
|
public static $labelField = "nombre";
|
|
|
|
protected $validationRules = [
|
|
"cif" => [
|
|
"label" => "LgProveedores.cif",
|
|
"rules" => "trim|max_length[15]",
|
|
],
|
|
"ciudad" => [
|
|
"label" => "LgProveedores.ciudad",
|
|
"rules" => "trim|max_length[255]",
|
|
],
|
|
"cp" => [
|
|
"label" => "LgProveedores.cp",
|
|
"rules" => "trim|max_length[10]",
|
|
],
|
|
"direccion" => [
|
|
"label" => "LgProveedores.direccion",
|
|
"rules" => "trim|max_length[255]",
|
|
],
|
|
"email" => [
|
|
"label" => "LgProveedores.email",
|
|
"rules" => "trim|max_length[255]|valid_email|permit_empty",
|
|
],
|
|
"nombre" => [
|
|
"label" => "LgProveedores.nombre",
|
|
"rules" => "trim|required|max_length[255]",
|
|
],
|
|
"persona_contacto" => [
|
|
"label" => "LgProveedores.personaContacto",
|
|
"rules" => "trim|max_length[255]",
|
|
],
|
|
"razon_social" => [
|
|
"label" => "LgProveedores.razonSocial",
|
|
"rules" => "trim|max_length[255]",
|
|
],
|
|
"telefono" => [
|
|
"label" => "LgProveedores.telefono",
|
|
"rules" => "trim|max_length[60]",
|
|
],
|
|
];
|
|
|
|
protected $validationMessages = [
|
|
"cif" => [
|
|
"max_length" => "LgProveedores.validation.cif.max_length",
|
|
],
|
|
"ciudad" => [
|
|
"max_length" => "LgProveedores.validation.ciudad.max_length",
|
|
],
|
|
"cp" => [
|
|
"max_length" => "LgProveedores.validation.cp.max_length",
|
|
],
|
|
"direccion" => [
|
|
"max_length" => "LgProveedores.validation.direccion.max_length",
|
|
],
|
|
"email" => [
|
|
"max_length" => "LgProveedores.validation.email.max_length",
|
|
"valid_email" => "LgProveedores.validation.email.valid_email",
|
|
],
|
|
"nombre" => [
|
|
"max_length" => "LgProveedores.validation.nombre.max_length",
|
|
"required" => "LgProveedores.validation.nombre.required",
|
|
],
|
|
"persona_contacto" => [
|
|
"max_length" => "LgProveedores.validation.persona_contacto.max_length",
|
|
],
|
|
"razon_social" => [
|
|
"max_length" => "LgProveedores.validation.razon_social.max_length",
|
|
],
|
|
"telefono" => [
|
|
"max_length" => "LgProveedores.validation.telefono.max_length",
|
|
],
|
|
];
|
|
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
|
|
{
|
|
$sql =
|
|
"SELECT t1." .
|
|
$selcols .
|
|
", t2.nombre AS tipo, t3.nombre AS provincia, t4.nombre AS pais FROM " .
|
|
$this->table .
|
|
" t1 LEFT JOIN lg_proveedores_tipos t2 ON t1.tipo_id = t2.id LEFT JOIN lg_provincias t3 ON t1.provincia_id = t3.id LEFT JOIN lg_paises t4 ON t1.pais_id = t4.id";
|
|
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.
|
|
*
|
|
* @param string $search
|
|
*
|
|
* @return \CodeIgniter\Database\BaseBuilder
|
|
*/
|
|
public function getResource(string $search = "")
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.id AS id, t1.nombre AS nombre, t1.razon_social AS razon_social, t1.cif AS cif, t1.direccion AS direccion, t1.cp AS cp, t1.ciudad AS ciudad, t1.persona_contacto AS persona_contacto, t1.email AS email, t1.telefono AS telefono, t2.nombre AS tipo, t3.nombre AS provincia, t4.nombre AS pais"
|
|
);
|
|
$builder->join("lg_proveedores_tipos t2", "t1.tipo_id = t2.id", "left");
|
|
$builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left");
|
|
$builder->join("lg_paises t4", "t1.pais_id = t4.id", "left");
|
|
|
|
return empty($search)
|
|
? $builder
|
|
: $builder
|
|
->groupStart()
|
|
->like("t1.id", $search)
|
|
->orLike("t1.nombre", $search)
|
|
->orLike("t1.razon_social", $search)
|
|
->orLike("t1.cif", $search)
|
|
->orLike("t1.direccion", $search)
|
|
->orLike("t1.cp", $search)
|
|
->orLike("t1.ciudad", $search)
|
|
->orLike("t1.persona_contacto", $search)
|
|
->orLike("t1.email", $search)
|
|
->orLike("t1.telefono", $search)
|
|
->orLike("t2.id", $search)
|
|
->orLike("t3.id", $search)
|
|
->orLike("t4.id", $search)
|
|
->orLike("t1.id", $search)
|
|
->orLike("t1.nombre", $search)
|
|
->orLike("t1.tipo_id", $search)
|
|
->orLike("t1.razon_social", $search)
|
|
->orLike("t1.cif", $search)
|
|
->orLike("t1.direccion", $search)
|
|
->orLike("t1.cp", $search)
|
|
->orLike("t1.ciudad", $search)
|
|
->orLike("t1.provincia_id", $search)
|
|
->orLike("t1.pais_id", $search)
|
|
->orLike("t1.persona_contacto", $search)
|
|
->orLike("t1.email", $search)
|
|
->orLike("t1.telefono", $search)
|
|
->orLike("t2.nombre", $search)
|
|
->orLike("t3.nombre", $search)
|
|
->orLike("t4.nombre", $search)
|
|
->groupEnd();
|
|
}
|
|
}
|