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

@ -215,7 +215,7 @@ $routes->group('papelesgenericos', ['namespace' => 'App\Controllers\Configuracio
$routes->post('datatable', 'Papelesgenericos::datatable', ['as' => 'dataTableOfPapelesGenericos']);
$routes->post('allmenuitems', 'Papelesgenericos::allItemsSelect', ['as' => 'select2ItemsOfPapelesGenericos']);
$routes->post('menuitems', 'Papelesgenericos::menuItems', ['as' => 'menuItemsOfPapelesGenericos']);
$routes->get('getpapelgenericocliente', 'Papelesgenericos::getPapelGenericoCliente', ['as' => 'getPapelGenericoCliente']);
$routes->get('getpapelcliente', 'Papelesgenericos::getPapelCliente', ['as' => 'getPapelCliente']);
});
$routes->resource('papelesgenericos', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Papelesgenericos', 'except' => 'show,new,create,update']);
@ -229,7 +229,6 @@ $routes->group('papelesimpresion', ['namespace' => 'App\Controllers\Configuracio
$routes->post('datatable', 'Papelesimpresion::datatable', ['as' => 'dataTableOfPapelesImpresion']);
$routes->post('allmenuitems', 'Papelesimpresion::allItemsSelect', ['as' => 'select2ItemsOfPapelesImpresion']);
$routes->post('menuitems', 'Papelesimpresion::menuItems', ['as' => 'menuItemsOfPapelesImpresion']);
$routes->get('getgramajecliente', 'Papelesimpresion::getGramajesCliente', ['as' => 'getGramajePresupuestoCliente']);
});
$routes->resource('papelesimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Papelesimpresion', 'except' => 'show,new,create,update']);

View File

@ -294,14 +294,15 @@ class Papelesgenericos extends \App\Controllers\BaseResourceController
}
}
public function getPapelGenericoCliente()
public function getPapelCliente()
{
if ($this->request->isAJAX()) {
$tipo = goSanitize($this->request->getGet('tipo'))[0];
$cubierta = goSanitize($this->request->getGet('text'))[0];
$selected_papel = goSanitize($this->request->getGet('papel'))[0] ?? null;
$cubierta = goSanitize($this->request->getGet('cubierta'))[0] ?? 0;
$papel_especial = goSanitize($this->request->getGet('papel_especial'))[0] ?? 0;
$menu = $this->model->getPapelGenericoCliente($tipo, $cubierta, $papel_especial);
$menu = $this->model->getPapelCliente($tipo, $cubierta, $selected_papel, $papel_especial);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();

View File

@ -437,26 +437,4 @@ class Papelesimpresion extends \App\Controllers\BaseResourceController
$ma_pa_model->updateRows($active_values);
}
}
public function getGramajesCliente(){
if ($this->request->isAJAX()) {
$papel_generico_id = goSanitize($this->request->getGet('papel'))[0];
$tipo = goSanitize($this->request->getGet('tipo'))[0];
$cubierta = goSanitize($this->request->getGet('text'))[0];
$papel_especial = goSanitize($this->request->getGet('papel_especial'))[0] ?? 0;
$menu = $this->model->getGramajePresupuestoCliente($papel_generico_id, $tipo, $cubierta, $papel_especial);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
'gramajes' => $menu,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

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;
}
}

View File

@ -350,55 +350,5 @@ class PapelImpresionModel extends \App\Models\BaseModel
return "";
}
public function getGramajePresupuestoCliente($papel_generico_id = -1, $tipo = 'interior', $cubierta = 0, $papel_especial = 0)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.gramaje AS text"
)
->join("lg_papel_generico t2", "t2.id = t1.papel_generico_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.is_deleted", 0)
->where("t1.isActivo", 1)
->where("t1.use_in_client", 1)
->where("t2.id", $papel_generico_id)
->where("t2.show_in_client", 1)
->where("t2.is_deleted", 0)
->where("t3.active", 1)
->where("t4.is_deleted", 0)
->where("t4.tipo", "impresion")
->where("t5.is_deleted", 0)
->where("t5.tipo", $tipo)
->distinct("t1.gramaje");
if($papel_especial){
$builder->where('t2.show_in_client_special');
}
$uso_tarifa = 'interior';
if ($cubierta) {
$uso_tarifa = 'cubierta';
$builder->where("t1.cubierta", 1);
} else {
if ($tipo == 'negro' || $tipo == 'negrohq')
$builder->where("t1.bn", 1);
else if ($tipo == 'color' || $tipo == 'colorhq')
$builder->where("t1.color", 1);
}
$builder->where("t5.uso", $uso_tarifa);
$values = $builder->orderBy("t1.gramaje", "asc")->get()->getResultObject();
foreach ($values as $value) {
$value->id = $value->text;
}
//$query=$this->db->getLastQuery();
return $values;
}
}