mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
159 lines
4.9 KiB
PHP
159 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Configuracion;
|
|
|
|
class PapelGenericoModel extends \App\Models\GoBaseModel
|
|
{
|
|
protected $table = "lg_papel_generico";
|
|
|
|
/**
|
|
* Whether primary key uses auto increment.
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $useAutoIncrement = true;
|
|
|
|
const SORTABLE = [
|
|
//0 => "t1.id",
|
|
0 => "t1.nombre",
|
|
1 => "t1.code",
|
|
2 => "t1.code_ot",
|
|
3 => "t1.show_in_client",
|
|
];
|
|
|
|
protected $allowedFields = ["nombre", "code", "code_ot", "show_in_client", "deleted_at", "is_deleted"];
|
|
protected $returnType = "App\Entities\Configuracion\PapelGenerico";
|
|
|
|
protected $useTimestamps = true;
|
|
protected $useSoftDeletes = false;
|
|
|
|
protected $createdField = "created_at";
|
|
|
|
protected $updatedField = "updated_at";
|
|
|
|
public static $labelField = "nombre";
|
|
|
|
protected $validationRules = [
|
|
"code" => [
|
|
"label" => "PapelGenericoes.code",
|
|
"rules" => "trim|max_length[5]",
|
|
],
|
|
"code_ot" => [
|
|
"label" => "PapelGenericoes.codeOt",
|
|
"rules" => "trim|max_length[5]",
|
|
],
|
|
"nombre" => [
|
|
"label" => "PapelGenericoes.nombre",
|
|
"rules" => "trim|required|max_length[255]",
|
|
],
|
|
];
|
|
|
|
protected $validationMessages = [
|
|
"code" => [
|
|
"max_length" => "PapelGenericoes.validation.code.max_length",
|
|
],
|
|
"code_ot" => [
|
|
"max_length" => "PapelGenericoes.validation.code_ot.max_length",
|
|
],
|
|
"nombre" => [
|
|
"max_length" => "PapelGenericoes.validation.nombre.max_length",
|
|
"required" => "PapelGenericoes.validation.nombre.required",
|
|
],
|
|
];
|
|
|
|
/**
|
|
* 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.code AS code, t1.code_ot AS code_ot, t1.show_in_client AS show_in_client"
|
|
)
|
|
->where("is_deleted", 0);
|
|
|
|
return empty($search)
|
|
? $builder
|
|
: $builder
|
|
->groupStart()
|
|
->like("t1.id", $search)
|
|
->orLike("t1.nombre", $search)
|
|
->orLike("t1.code", $search)
|
|
->orLike("t1.code_ot", $search)
|
|
->orLike("t1.id", $search)
|
|
->orLike("t1.nombre", $search)
|
|
->orLike("t1.code", $search)
|
|
->orLike("t1.code_ot", $search)
|
|
->groupEnd();
|
|
}
|
|
|
|
|
|
public function getPapelForComparador($tipo, $is_cubierta = null, $is_sobrecubierta = null)
|
|
{
|
|
/*
|
|
1.-> Tipo impresion
|
|
2.-> Maquina
|
|
3.-> Papeles impresion asociados a esa maquina
|
|
4.-> papeles genericos que aparecen en esos papeles impresion
|
|
*/
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.nombre AS papel_generico"
|
|
)
|
|
->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "left")
|
|
->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "left")
|
|
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left")
|
|
->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "left")
|
|
|
|
->where("t1.is_deleted", 0)
|
|
->where("t2.is_deleted", 0)
|
|
->where("t4.is_deleted", 0)
|
|
->where("t4.tipo", "impresion")
|
|
->where("t5.tipo", $tipo);
|
|
|
|
if(!is_null($is_cubierta)){
|
|
if($is_cubierta==true){
|
|
$builder->where("t2.cubierta", 1);
|
|
}
|
|
else if($is_sobrecubierta==true){
|
|
$builder->where("t2.sobrecubierta", 1);
|
|
}
|
|
}
|
|
|
|
return array_unique(array_column($builder->orderBy("t1.nombre", "asc")->get()->getResultArray(), 'papel_generico'));
|
|
}
|
|
|
|
public function getGramajeComparador(string $papel_generico_nombre="")
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t2.gramaje AS text"
|
|
)
|
|
->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "left")
|
|
|
|
->where("t1.is_deleted", 0)
|
|
->where("t2.is_deleted", 0)
|
|
->where("t1.nombre", $papel_generico_nombre);
|
|
|
|
$values = $builder->orderBy("t2.gramaje", "asc")->get()->getResultObject();
|
|
$id = 1;
|
|
foreach ($values as $value){
|
|
$value->id = $id;
|
|
$id++;
|
|
}
|
|
$values_array = array_map( function( $value ) {
|
|
return $value->text;
|
|
}, $values );
|
|
$unique_values = array_unique($values_array);
|
|
return array_values(array_intersect_key($values, $unique_values));
|
|
|
|
}
|
|
}
|