selectores de papel y gramaje. falta validacion

This commit is contained in:
2024-11-21 21:57:06 +01:00
parent 9a19c67cd9
commit 19bd409efa
7 changed files with 70 additions and 96 deletions

View File

@ -313,7 +313,7 @@ class PapelGenericoModel extends \App\Models\BaseModel
}
public function getPapelGenericoCliente($tipo, $is_cubierta = false, $papel_especial = false)
public function getPapelCliente($tipo, $is_cubierta = false, $selected_papel_id = null, $papel_especial = false)
{
/*
1.-> Tipo impresion
@ -321,10 +321,37 @@ class PapelGenericoModel extends \App\Models\BaseModel
3.-> Papeles impresion asociados a esa maquina
4.-> papeles genericos que aparecen en esos papeles impresion
*/
$builder = $this->db
if ($selected_papel_id != null) {
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id as id, t1.nombre AS nombre"
"t2.gramaje as gramaje",
// for debug, t2.nombre AS nombre_papel_impresion, t4.nombre AS maquina_nombre, t5.uso AS tarifa_uso, t5.tipo AS tarifa_tipo"
)
->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "inner")
->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "inner")
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "inner")
->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "inner")
->where("t1.id", $selected_papel_id)
->where("t1.is_deleted", 0)
->where("t1.show_in_client", 1)
->where("t2.is_deleted", 0)
->where("t2.isActivo", 1)
->where("t2.use_in_client", 1)
->where("t3.active", 1)
->where("t4.is_deleted", 0)
->where("t4.tipo", "impresion")
->where("t5.is_deleted", 0)
->where("t5.tipo", $tipo)
->distinct('t2.gramaje');
}
else{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id as id, t1.nombre AS nombre",
// for debug, t2.nombre AS nombre_papel_impresion, t4.nombre AS maquina_nombre, t5.uso AS tarifa_uso, t5.tipo AS tarifa_tipo"
)
->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "inner")
@ -343,26 +370,38 @@ class PapelGenericoModel extends \App\Models\BaseModel
->where("t5.is_deleted", 0)
->where("t5.tipo", $tipo)
->distinct('t1.id');
$builder->groupStart()
->where("t2.id IS NOT NULL") // Validar relación con `t2`
->orWhere("t4.id IS NOT NULL") // Validar relación con `t4`
->groupEnd();
}
// Validación adicional para asegurar que t1.id esté presente en las combinaciones con t3.active = 1
$builder->whereIn("t1.id", function ($subQuery) {
$subQuery->select("t1_inner.id")
->from("lg_papel_generico t1_inner")
->join("lg_papel_impresion t2_inner", "t2_inner.papel_generico_id = t1_inner.id", "inner")
->join("lg_maquina_papel_impresion t3_inner", "t3_inner.papel_impresion_id = t2_inner.id", "inner")
->where("t3_inner.active", 1);
});
if ($is_cubierta == true) {
$builder->where("t2.cubierta", 1);
$builder->where("t5.uso", 'cubierta');
} else {
$builder->where("t5.uso", 'interior');
if ($tipo == 'negro' || $tipo == 'negrohq')
$builder->where("t2.bn", 1);
else if ($tipo == 'color' || $tipo == 'colorhq')
$builder->where("t2.color", 1);
}
if ($papel_especial == true) {
$builder->where("t1.show_in_client_special", 1);
}
if ($tipo == 'colorhq' || $tipo == 'negrohq') {
$builder->where("t2.rotativa", 0);
}
$data = $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
//var_dump($this->db->getLastQuery());
//$query = $this->db->getLastQuery();
return $data;
}
}