mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadido clientes by Ozar y primeros fixes
This commit is contained in:
373
ci4/app/Models/Clientes/ClienteModel.php
Normal file
373
ci4/app/Models/Clientes/ClienteModel.php
Normal file
@ -0,0 +1,373 @@
|
||||
<?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.email",
|
||||
3 => "t1.salesman_id",
|
||||
4 => "t1.forma_pago_id",
|
||||
5 => "t1.vencimiento",
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
"nombre",
|
||||
"alias",
|
||||
"direccion",
|
||||
"ciudad",
|
||||
"comunidad_autonoma_id",
|
||||
"provincia",
|
||||
"cp",
|
||||
"pais_id",
|
||||
"telefono",
|
||||
"email",
|
||||
"salesman_id",
|
||||
"soporte_id",
|
||||
"forma_pago_id",
|
||||
"vencimiento",
|
||||
"fechaVencimiento",
|
||||
"margen",
|
||||
"margen_pod",
|
||||
"descuento",
|
||||
"limite_credito",
|
||||
"limite_credito_user_id",
|
||||
"limite_credito_change_at",
|
||||
"creditoSolunion",
|
||||
"creditoAsegurado",
|
||||
"ccc",
|
||||
"ccc_customer",
|
||||
"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",
|
||||
"user_created_id",
|
||||
"user_update_id",
|
||||
];
|
||||
protected $returnType = "App\Entities\Clientes\ClienteEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "nombre";
|
||||
|
||||
protected $validationRules = [
|
||||
"alias" => [
|
||||
"label" => "Cliente.alias",
|
||||
"rules" => "trim|required|max_length[255]",
|
||||
],
|
||||
"ccc" => [
|
||||
"label" => "Cliente.ccc",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
"ccc_customer" => [
|
||||
"label" => "Cliente.cccCustomer",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
"ciudad" => [
|
||||
"label" => "Cliente.ciudad",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
"comentarios" => [
|
||||
"label" => "Cliente.comentarios",
|
||||
"rules" => "trim|max_length[16313]",
|
||||
],
|
||||
"comentarios_produccion" => [
|
||||
"label" => "Cliente.comentariosProduccion",
|
||||
"rules" => "trim|max_length[16313]",
|
||||
],
|
||||
"comentarios_tirada_flexible" => [
|
||||
"label" => "Cliente.comentariosTiradaFlexible",
|
||||
"rules" => "trim|required|max_length[16313]",
|
||||
],
|
||||
"cp" => [
|
||||
"label" => "Cliente.cp",
|
||||
"rules" => "trim|max_length[10]",
|
||||
],
|
||||
"creditoSolunion" => [
|
||||
"label" => "Cliente.creditosolunion",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
"descuento" => [
|
||||
"label" => "Cliente.descuento",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"descuento_tirada_flexible" => [
|
||||
"label" => "Cliente.descuentoTiradaFlexible",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"direccion" => [
|
||||
"label" => "Cliente.direccion",
|
||||
"rules" => "trim|max_length[300]",
|
||||
],
|
||||
"email" => [
|
||||
"label" => "Cliente.email",
|
||||
"rules" => "trim|max_length[150]|valid_email|permit_empty",
|
||||
],
|
||||
"fechaVencimiento" => [
|
||||
"label" => "Cliente.fechavencimiento",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
"limite_credito" => [
|
||||
"label" => "Cliente.limiteCredito",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"limite_credito_change_at" => [
|
||||
"label" => "Cliente.limiteCreditoChangeAt",
|
||||
"rules" => "required|valid_date",
|
||||
],
|
||||
"limite_credito_user_id" => [
|
||||
"label" => "Cliente.limiteCreditoUserId",
|
||||
"rules" => "required|integer",
|
||||
],
|
||||
"margen" => [
|
||||
"label" => "Cliente.margen",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"margen_plantilla_id" => [
|
||||
"label" => "Cliente.margenPlantillaId",
|
||||
"rules" => "integer|permit_empty",
|
||||
],
|
||||
"margen_pod" => [
|
||||
"label" => "Cliente.margenPod",
|
||||
"rules" => "decimal|permit_empty",
|
||||
],
|
||||
"nombre" => [
|
||||
"label" => "Cliente.nombre",
|
||||
"rules" => "trim|required|max_length[255]",
|
||||
],
|
||||
"num_cuenta" => [
|
||||
"label" => "Cliente.numCuenta",
|
||||
"rules" => "trim|max_length[10]",
|
||||
],
|
||||
"provincia" => [
|
||||
"label" => "Cliente.provincia",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
"ps_customer_id" => [
|
||||
"label" => "Cliente.psCustomerId",
|
||||
"rules" => "integer|permit_empty",
|
||||
],
|
||||
"salesman_id" => [
|
||||
"label" => "Cliente.salesmanId",
|
||||
"rules" => "required|integer",
|
||||
],
|
||||
"saturacion" => [
|
||||
"label" => "Cliente.saturacion",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"soporte_id" => [
|
||||
"label" => "Cliente.soporteId",
|
||||
"rules" => "integer|permit_empty",
|
||||
],
|
||||
"telefono" => [
|
||||
"label" => "Cliente.telefono",
|
||||
"rules" => "trim|max_length[60]",
|
||||
],
|
||||
"tienda_id" => [
|
||||
"label" => "Cliente.tiendaId",
|
||||
"rules" => "integer|permit_empty",
|
||||
],
|
||||
"user_created_id" => [
|
||||
"label" => "Cliente.userCreatedId",
|
||||
"rules" => "required|integer",
|
||||
],
|
||||
"user_update_id" => [
|
||||
"label" => "Cliente.userUpdateId",
|
||||
"rules" => "required|integer",
|
||||
],
|
||||
"vencimiento" => [
|
||||
"label" => "Cliente.vencimiento",
|
||||
"rules" => "required|integer",
|
||||
],
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
"alias" => [
|
||||
"max_length" => "Cliente.validation.alias.max_length",
|
||||
"required" => "Cliente.validation.alias.required",
|
||||
],
|
||||
"ccc" => [
|
||||
"max_length" => "Cliente.validation.ccc.max_length",
|
||||
],
|
||||
"ccc_customer" => [
|
||||
"max_length" => "Cliente.validation.ccc_customer.max_length",
|
||||
],
|
||||
"ciudad" => [
|
||||
"max_length" => "Cliente.validation.ciudad.max_length",
|
||||
],
|
||||
"comentarios" => [
|
||||
"max_length" => "Cliente.validation.comentarios.max_length",
|
||||
],
|
||||
"comentarios_produccion" => [
|
||||
"max_length" => "Cliente.validation.comentarios_produccion.max_length",
|
||||
],
|
||||
"comentarios_tirada_flexible" => [
|
||||
"max_length" => "Cliente.validation.comentarios_tirada_flexible.max_length",
|
||||
"required" => "Cliente.validation.comentarios_tirada_flexible.required",
|
||||
],
|
||||
"cp" => [
|
||||
"max_length" => "Cliente.validation.cp.max_length",
|
||||
],
|
||||
"creditoSolunion" => [
|
||||
"max_length" => "Cliente.validation.creditoSolunion.max_length",
|
||||
],
|
||||
"descuento" => [
|
||||
"decimal" => "Cliente.validation.descuento.decimal",
|
||||
"required" => "Cliente.validation.descuento.required",
|
||||
],
|
||||
"descuento_tirada_flexible" => [
|
||||
"decimal" => "Cliente.validation.descuento_tirada_flexible.decimal",
|
||||
"required" => "Cliente.validation.descuento_tirada_flexible.required",
|
||||
],
|
||||
"direccion" => [
|
||||
"max_length" => "Cliente.validation.direccion.max_length",
|
||||
],
|
||||
"email" => [
|
||||
"max_length" => "Cliente.validation.email.max_length",
|
||||
"valid_email" => "Cliente.validation.email.valid_email",
|
||||
],
|
||||
"fechaVencimiento" => [
|
||||
"max_length" => "Cliente.validation.fechaVencimiento.max_length",
|
||||
],
|
||||
"limite_credito" => [
|
||||
"decimal" => "Cliente.validation.limite_credito.decimal",
|
||||
"required" => "Cliente.validation.limite_credito.required",
|
||||
],
|
||||
"limite_credito_change_at" => [
|
||||
"required" => "Cliente.validation.limite_credito_change_at.required",
|
||||
"valid_date" => "Cliente.validation.limite_credito_change_at.valid_date",
|
||||
],
|
||||
"limite_credito_user_id" => [
|
||||
"integer" => "Cliente.validation.limite_credito_user_id.integer",
|
||||
"required" => "Cliente.validation.limite_credito_user_id.required",
|
||||
],
|
||||
"margen" => [
|
||||
"decimal" => "Cliente.validation.margen.decimal",
|
||||
"required" => "Cliente.validation.margen.required",
|
||||
],
|
||||
"margen_plantilla_id" => [
|
||||
"integer" => "Cliente.validation.margen_plantilla_id.integer",
|
||||
],
|
||||
"margen_pod" => [
|
||||
"decimal" => "Cliente.validation.margen_pod.decimal",
|
||||
],
|
||||
"nombre" => [
|
||||
"max_length" => "Cliente.validation.nombre.max_length",
|
||||
"required" => "Cliente.validation.nombre.required",
|
||||
],
|
||||
"num_cuenta" => [
|
||||
"max_length" => "Cliente.validation.num_cuenta.max_length",
|
||||
],
|
||||
"provincia" => [
|
||||
"max_length" => "Cliente.validation.provincia.max_length",
|
||||
],
|
||||
"ps_customer_id" => [
|
||||
"integer" => "Cliente.validation.ps_customer_id.integer",
|
||||
],
|
||||
"salesman_id" => [
|
||||
"integer" => "Cliente.validation.salesman_id.integer",
|
||||
"required" => "Cliente.validation.salesman_id.required",
|
||||
],
|
||||
"saturacion" => [
|
||||
"decimal" => "Cliente.validation.saturacion.decimal",
|
||||
"required" => "Cliente.validation.saturacion.required",
|
||||
],
|
||||
"soporte_id" => [
|
||||
"integer" => "Cliente.validation.soporte_id.integer",
|
||||
],
|
||||
"telefono" => [
|
||||
"max_length" => "Cliente.validation.telefono.max_length",
|
||||
],
|
||||
"tienda_id" => [
|
||||
"integer" => "Cliente.validation.tienda_id.integer",
|
||||
],
|
||||
"user_created_id" => [
|
||||
"integer" => "Cliente.validation.user_created_id.integer",
|
||||
"required" => "Cliente.validation.user_created_id.required",
|
||||
],
|
||||
"user_update_id" => [
|
||||
"integer" => "Cliente.validation.user_update_id.integer",
|
||||
"required" => "Cliente.validation.user_update_id.required",
|
||||
],
|
||||
"vencimiento" => [
|
||||
"integer" => "Cliente.validation.vencimiento.integer",
|
||||
"required" => "Cliente.validation.vencimiento.required",
|
||||
],
|
||||
];
|
||||
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
|
||||
{
|
||||
$sql =
|
||||
"SELECT t1." .
|
||||
$selcols .
|
||||
", t2.nombre AS pais, t3.nombre AS forma_pago FROM " .
|
||||
$this->table .
|
||||
" t1 LEFT JOIN lg_paises t2 ON t1.pais_id = t2.id LEFT JOIN lg_formas_pago t3 ON t1.forma_pago_id = t3.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.direccion AS direccion, t1.ciudad AS ciudad, t1.comunidad_autonoma_id AS comunidad_autonoma_id, t1.provincia AS provincia, t1.cp AS cp, t1.telefono AS telefono, t1.email AS email, t1.salesman_id AS salesman_id, t1.soporte_id AS soporte_id, t1.vencimiento AS vencimiento, t1.fechaVencimiento AS fechaVencimiento, t1.margen AS margen, t1.margen_pod AS margen_pod, t1.descuento AS descuento, t1.limite_credito AS limite_credito, t1.limite_credito_user_id AS limite_credito_user_id, t1.limite_credito_change_at AS limite_credito_change_at, t1.creditoSolunion AS creditoSolunion, t1.creditoAsegurado AS creditoAsegurado, t1.ccc AS ccc, t1.ccc_customer AS ccc_customer, t1.num_cuenta AS num_cuenta, t1.disponible_fe AS disponible_fe, t1.message_tracking AS message_tracking, t1.message_production_start AS message_production_start, t1.tirada_flexible AS tirada_flexible, t1.descuento_tirada_flexible AS descuento_tirada_flexible, t1.comentarios_tirada_flexible AS comentarios_tirada_flexible, t1.saturacion AS saturacion, t1.tienda_id AS tienda_id, t1.margen_plantilla_id AS margen_plantilla_id, t1.comentarios_produccion AS comentarios_produccion, t1.ps_customer_id AS ps_customer_id, t1.lineasEnvioFactura AS lineasEnvioFactura, t1.comentarios AS comentarios, t1.created_at AS created_at, t1.updated_at AS updated_at, t1.user_created_id AS user_created_id, t1.user_update_id AS user_update_id, t2.nombre AS pais, t3.nombre AS forma_pago"
|
||||
);
|
||||
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
|
||||
$builder->join("lg_formas_pago t3", "t1.forma_pago_id = t3.id", "left");
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.nombre", $search)
|
||||
->orLike("t1.alias", $search)
|
||||
->orLike("t1.email", $search)
|
||||
->orLike("t1.salesman_id", $search)
|
||||
->orLike("t1.vencimiento", $search)
|
||||
->orLike("t1.fechaVencimiento", $search)
|
||||
|
||||
->groupEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user