cambiada lista de clientes a nuevo formato

This commit is contained in:
2024-12-15 10:49:49 +01:00
parent c0297b6cba
commit ba793730f3
7 changed files with 244 additions and 162 deletions

View File

@ -14,13 +14,14 @@ class ClienteModel extends \App\Models\BaseModel
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",
0 => "t1.id",
1 => "t1.nombre",
2 => "t1.alias",
3 => "t1.cif",
4 => "t1.email",
5 => "t1.comercial_id",
6 => "t1.forma_pago_id",
7 => "t1.vencimiento",
];
protected $allowedFields = [
@ -63,7 +64,7 @@ class ClienteModel extends \App\Models\BaseModel
];
protected $returnType = "App\Entities\Clientes\ClienteEntity";
protected $deletedField = 'deleted_at';
protected $deletedField = 'deleted_at';
public static $labelField = "nombre";
@ -245,7 +246,7 @@ class ClienteModel extends \App\Models\BaseModel
"required" => "Clientes.validation.vencimiento.required",
],
];
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
public function findAllWithAllRelations($selcols = "*", int $limit = null, int $offset = 0)
{
$sql =
"SELECT t1." .
@ -279,35 +280,30 @@ class ClienteModel extends \App\Models\BaseModel
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "")
public function getResource($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);;
->where("is_deleted", 0);
;
$builder->join("users t5", "t1.comercial_id = t5.id", "left");
$builder->join("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", $search)
->orLike("t5.first_name", $search)
->orLike("t5.last_name", $search)
->orLike("t7.id", $search)
->orLike("t7.nombre", $search)
->groupEnd();
if (empty($search))
return $builder;
else {
$builder->groupStart();
foreach ($search as $col_search) {
$column = self::SORTABLE[$col_search[0]];
$value = $col_search[2];
$builder->where("LOWER(CONVERT($column USING utf8)) COLLATE utf8_general_ci LIKE", "%" . strtolower($value) . "%");
}
$builder->groupEnd();
return $builder;
}
}
/*
@ -353,7 +349,7 @@ class ClienteModel extends \App\Models\BaseModel
->join("pedidos", "pedidos.id = pedidos_linea.pedido_id", "left")
->join("facturas_pedidos_lineas", "facturas_pedidos_lineas.pedido_linea_id = pedidos_linea.id", "left")
->where("t1.id", $cliente_id);
$data = $query->get()->getResultObject();
$data = $query->get()->getResultObject();
$facturas = [];
$presupuestos = [];
$pedidos = [];