mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
374 lines
13 KiB
PHP
374 lines
13 KiB
PHP
<?php
|
|
namespace App\Models\Clientes;
|
|
|
|
class ClienteModel extends \App\Models\GoBaseModel
|
|
{
|
|
protected $table = "clientes";
|
|
|
|
/**
|
|
* Whether primary key uses auto increment.
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $useAutoIncrement = true;
|
|
|
|
const SORTABLE = [
|
|
0 => "t1.nombre",
|
|
1 => "t1.alias",
|
|
2 => "t1.cif",
|
|
3 => "t1.email",
|
|
4 => "t1.comercial_id",
|
|
5 => "t1.forma_pago_id",
|
|
6 => "t1.vencimiento",
|
|
];
|
|
|
|
protected $allowedFields = [
|
|
"nombre",
|
|
"alias",
|
|
"cif",
|
|
"direccion",
|
|
"ciudad",
|
|
"comunidad_autonoma_id",
|
|
"provincia_id",
|
|
"cp",
|
|
"pais_id",
|
|
"telefono",
|
|
"email",
|
|
"comercial_id",
|
|
"soporte_id",
|
|
"forma_pago_id",
|
|
"vencimiento",
|
|
"fecha_vencimiento",
|
|
"margen",
|
|
"margen_pod",
|
|
"descuento",
|
|
"limite_credito",
|
|
"limite_credito_user_id",
|
|
"limite_credito_change_at",
|
|
"credito_solunion",
|
|
"credito_asegurado",
|
|
"ccc",
|
|
"ccc_cliente",
|
|
"num_cuenta",
|
|
"disponible_fe",
|
|
"message_tracking",
|
|
"message_production_start",
|
|
"tirada_flexible",
|
|
"descuento_tirada_flexible",
|
|
"comentarios_tirada_flexible",
|
|
"saturacion",
|
|
"tienda_id",
|
|
"margen_plantilla_id",
|
|
"comentarios_produccion",
|
|
"ps_customer_id",
|
|
"lineasEnvioFactura",
|
|
"comentarios",
|
|
"is_deleted",
|
|
"deleted_at",
|
|
"user_created_id",
|
|
"user_update_id",
|
|
];
|
|
protected $returnType = "App\Entities\Clientes\ClienteEntity";
|
|
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
public static $labelField = "nombre";
|
|
|
|
protected $validationRules = [
|
|
"alias" => [
|
|
"label" => "Clientes.alias",
|
|
"rules" => "trim|required|max_length[255]",
|
|
],
|
|
"ccc" => [
|
|
"label" => "Clientes.ccc",
|
|
"rules" => "trim|max_length[100]",
|
|
],
|
|
"ccc_cliente" => [
|
|
"label" => "Clientes.cccCliente",
|
|
"rules" => "trim|max_length[100]",
|
|
],
|
|
"cif" => [
|
|
"label" => "Clientes.cif",
|
|
"rules" => "trim|required|max_length[50]",
|
|
],
|
|
"ciudad" => [
|
|
"label" => "Clientes.ciudad",
|
|
"rules" => "trim|max_length[100]",
|
|
],
|
|
"comentarios" => [
|
|
"label" => "Clientes.comentarios",
|
|
"rules" => "trim|max_length[16313]",
|
|
],
|
|
"comentarios_produccion" => [
|
|
"label" => "Clientes.comentariosProduccion",
|
|
"rules" => "trim|max_length[16313]",
|
|
],
|
|
"comentarios_tirada_flexible" => [
|
|
"label" => "Clientes.comentariosTiradaFlexible",
|
|
"rules" => "trim|required|max_length[16313]",
|
|
],
|
|
"cp" => [
|
|
"label" => "Clientes.cp",
|
|
"rules" => "trim|max_length[10]",
|
|
],
|
|
"credito_solunion" => [
|
|
"label" => "Clientes.creditoSolunion",
|
|
"rules" => "trim|max_length[100]",
|
|
],
|
|
"descuento" => [
|
|
"label" => "Clientes.descuento",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"descuento_tirada_flexible" => [
|
|
"label" => "Clientes.descuentoTiradaFlexible",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"direccion" => [
|
|
"label" => "Clientes.direccion",
|
|
"rules" => "trim|max_length[300]",
|
|
],
|
|
"email" => [
|
|
"label" => "Clientes.email",
|
|
"rules" => "trim|max_length[150]|valid_email|permit_empty",
|
|
],
|
|
"fecha_vencimiento" => [
|
|
"label" => "Clientes.fechaVencimiento",
|
|
"rules" => "trim|max_length[100]",
|
|
],
|
|
"is_deleted" => [
|
|
"label" => "Clientes.isDeleted",
|
|
"rules" => "required|integer",
|
|
],
|
|
"limite_credito" => [
|
|
"label" => "Clientes.limiteCredito",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"limite_credito_change_at" => [
|
|
"label" => "Clientes.limiteCreditoChangeAt",
|
|
"rules" => "required|valid_date",
|
|
],
|
|
"limite_credito_user_id" => [
|
|
"label" => "Clientes.limiteCreditoUserId",
|
|
"rules" => "required|integer",
|
|
],
|
|
"margen" => [
|
|
"label" => "Clientes.margen",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"margen_plantilla_id" => [
|
|
"label" => "Clientes.margenPlantillaId",
|
|
"rules" => "integer|permit_empty",
|
|
],
|
|
"margen_pod" => [
|
|
"label" => "Clientes.margenPod",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"nombre" => [
|
|
"label" => "Clientes.nombre",
|
|
"rules" => "trim|required|max_length[255]",
|
|
],
|
|
"num_cuenta" => [
|
|
"label" => "Clientes.numCuenta",
|
|
"rules" => "trim|max_length[10]",
|
|
],
|
|
"ps_customer_id" => [
|
|
"label" => "Clientes.psCustomerId",
|
|
"rules" => "integer|permit_empty",
|
|
],
|
|
"saturacion" => [
|
|
"label" => "Clientes.saturacion",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"telefono" => [
|
|
"label" => "Clientes.telefono",
|
|
"rules" => "trim|max_length[60]",
|
|
],
|
|
"tienda_id" => [
|
|
"label" => "Clientes.tiendaId",
|
|
"rules" => "integer|permit_empty",
|
|
],
|
|
"user_created_id" => [
|
|
"label" => "Clientes.userCreatedId",
|
|
"rules" => "required|integer",
|
|
],
|
|
"user_update_id" => [
|
|
"label" => "Clientes.userUpdateId",
|
|
"rules" => "required|integer",
|
|
],
|
|
"vencimiento" => [
|
|
"label" => "Clientes.vencimiento",
|
|
"rules" => "required|integer",
|
|
],
|
|
];
|
|
|
|
protected $validationMessages = [
|
|
"alias" => [
|
|
"max_length" => "Clientes.validation.alias.max_length",
|
|
"required" => "Clientes.validation.alias.required",
|
|
],
|
|
"ccc" => [
|
|
"max_length" => "Clientes.validation.ccc.max_length",
|
|
],
|
|
"ccc_cliente" => [
|
|
"max_length" => "Clientes.validation.ccc_cliente.max_length",
|
|
],
|
|
"cif" => [
|
|
"max_length" => "Clientes.validation.cif.max_length",
|
|
"required" => "Clientes.validation.cif.required",
|
|
],
|
|
"ciudad" => [
|
|
"max_length" => "Clientes.validation.ciudad.max_length",
|
|
],
|
|
"comentarios" => [
|
|
"max_length" => "Clientes.validation.comentarios.max_length",
|
|
],
|
|
"comentarios_produccion" => [
|
|
"max_length" => "Clientes.validation.comentarios_produccion.max_length",
|
|
],
|
|
"comentarios_tirada_flexible" => [
|
|
"max_length" => "Clientes.validation.comentarios_tirada_flexible.max_length",
|
|
"required" => "Clientes.validation.comentarios_tirada_flexible.required",
|
|
],
|
|
"cp" => [
|
|
"max_length" => "Clientes.validation.cp.max_length",
|
|
],
|
|
"credito_solunion" => [
|
|
"max_length" => "Clientes.validation.credito_solunion.max_length",
|
|
],
|
|
"descuento" => [
|
|
"decimal" => "Clientes.validation.descuento.decimal",
|
|
"required" => "Clientes.validation.descuento.required",
|
|
],
|
|
"descuento_tirada_flexible" => [
|
|
"decimal" => "Clientes.validation.descuento_tirada_flexible.decimal",
|
|
"required" => "Clientes.validation.descuento_tirada_flexible.required",
|
|
],
|
|
"direccion" => [
|
|
"max_length" => "Clientes.validation.direccion.max_length",
|
|
],
|
|
"email" => [
|
|
"max_length" => "Clientes.validation.email.max_length",
|
|
"valid_email" => "Clientes.validation.email.valid_email",
|
|
],
|
|
"fecha_vencimiento" => [
|
|
"max_length" => "Clientes.validation.fecha_vencimiento.max_length",
|
|
],
|
|
"is_deleted" => [
|
|
"integer" => "Clientes.validation.is_deleted.integer",
|
|
"required" => "Clientes.validation.is_deleted.required",
|
|
],
|
|
"limite_credito" => [
|
|
"decimal" => "Clientes.validation.limite_credito.decimal",
|
|
"required" => "Clientes.validation.limite_credito.required",
|
|
],
|
|
"limite_credito_change_at" => [
|
|
"required" => "Clientes.validation.limite_credito_change_at.required",
|
|
"valid_date" => "Clientes.validation.limite_credito_change_at.valid_date",
|
|
],
|
|
"limite_credito_user_id" => [
|
|
"integer" => "Clientes.validation.limite_credito_user_id.integer",
|
|
"required" => "Clientes.validation.limite_credito_user_id.required",
|
|
],
|
|
"margen" => [
|
|
"decimal" => "Clientes.validation.margen.decimal",
|
|
"required" => "Clientes.validation.margen.required",
|
|
],
|
|
"margen_plantilla_id" => [
|
|
"integer" => "Clientes.validation.margen_plantilla_id.integer",
|
|
],
|
|
"margen_pod" => [
|
|
"decimal" => "Clientes.validation.margen_pod.decimal",
|
|
],
|
|
"nombre" => [
|
|
"max_length" => "Clientes.validation.nombre.max_length",
|
|
"required" => "Clientes.validation.nombre.required",
|
|
],
|
|
"num_cuenta" => [
|
|
"max_length" => "Clientes.validation.num_cuenta.max_length",
|
|
],
|
|
"ps_customer_id" => [
|
|
"integer" => "Clientes.validation.ps_customer_id.integer",
|
|
],
|
|
"saturacion" => [
|
|
"decimal" => "Clientes.validation.saturacion.decimal",
|
|
"required" => "Clientes.validation.saturacion.required",
|
|
],
|
|
"telefono" => [
|
|
"max_length" => "Clientes.validation.telefono.max_length",
|
|
],
|
|
"tienda_id" => [
|
|
"integer" => "Clientes.validation.tienda_id.integer",
|
|
],
|
|
"user_created_id" => [
|
|
"integer" => "Clientes.validation.user_created_id.integer",
|
|
"required" => "Clientes.validation.user_created_id.required",
|
|
],
|
|
"user_update_id" => [
|
|
"integer" => "Clientes.validation.user_update_id.integer",
|
|
"required" => "Clientes.validation.user_update_id.required",
|
|
],
|
|
"vencimiento" => [
|
|
"integer" => "Clientes.validation.vencimiento.integer",
|
|
"required" => "Clientes.validation.vencimiento.required",
|
|
],
|
|
];
|
|
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
|
|
{
|
|
$sql =
|
|
"SELECT t1." .
|
|
$selcols .
|
|
", t2.nombre AS comunidad_autonoma_id, t3.nombre AS provincia, t4.nombre AS pais_id, t5.first_name AS comercial, t6.last_name AS soporte, t7.nombre AS forma_pago_id FROM " .
|
|
$this->table .
|
|
" t1 LEFT JOIN lg_comunidades_autonomas t2 ON t1.comunidad_autonoma_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 LEFT JOIN auth_user t5 ON t1.comercial_id = t5.id_user LEFT JOIN auth_user t6 ON t1.soporte_id = t6.id_user LEFT JOIN lg_formas_pago t7 ON t1.forma_pago_id = t7.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.alias AS alias, t1.cif AS cif, t1.email AS email, t1.vencimiento AS vencimiento, t5.first_name AS comercial, t7.nombre AS forma_pago_id"
|
|
)
|
|
->where("is_deleted", 0);;
|
|
$builder->join("auth_user t5", "t1.comercial_id = t5.id_user", "left");
|
|
$builder->join("lg_formas_pago t7", "t1.forma_pago_id = t7.id", "left");
|
|
|
|
|
|
return empty($search)
|
|
? $builder
|
|
: $builder
|
|
->groupStart()
|
|
->like("t1.nombre", $search)
|
|
->orLike("t1.alias", $search)
|
|
->orLike("t1.cif", $search)
|
|
->orLike("t1.email", $search)
|
|
->orLike("t1.soporte_id", $search)
|
|
->orLike("t1.forma_pago_id", $search)
|
|
->orLike("t1.vencimiento", $search)
|
|
->orLike("t5.id_user", $search)
|
|
->orLike("t5.first_name", $search)
|
|
->orLike("t5.last_name", $search)
|
|
->orLike("t7.id", $search)
|
|
->orLike("t7.nombre", $search)
|
|
->groupEnd();
|
|
}
|
|
}
|