diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index b9a084cf..b8b47ff1 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -215,6 +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->resource('papelesgenericos', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Papelesgenericos', 'except' => 'show,new,create,update']); @@ -228,6 +229,7 @@ $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']); diff --git a/ci4/app/Controllers/Configuracion/Papelesgenericos.php b/ci4/app/Controllers/Configuracion/Papelesgenericos.php index af7cfa22..bc439726 100755 --- a/ci4/app/Controllers/Configuracion/Papelesgenericos.php +++ b/ci4/app/Controllers/Configuracion/Papelesgenericos.php @@ -293,4 +293,25 @@ class Papelesgenericos extends \App\Controllers\BaseResourceController return $this->failUnauthorized('Invalid request', 403); } } + + public function getPapelGenericoCliente() + { + if ($this->request->isAJAX()) { + + $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->getPapelGenericoCliente($tipo, $cubierta, $papel_especial); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'papeles' => $menu, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Controllers/Configuracion/Papelesimpresion.php b/ci4/app/Controllers/Configuracion/Papelesimpresion.php index b92d69a8..931c3f30 100755 --- a/ci4/app/Controllers/Configuracion/Papelesimpresion.php +++ b/ci4/app/Controllers/Configuracion/Papelesimpresion.php @@ -444,4 +444,26 @@ 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); + } + } } diff --git a/ci4/app/Models/Configuracion/PapelGenericoModel.php b/ci4/app/Models/Configuracion/PapelGenericoModel.php index 7cd2ca73..5d110abf 100755 --- a/ci4/app/Models/Configuracion/PapelGenericoModel.php +++ b/ci4/app/Models/Configuracion/PapelGenericoModel.php @@ -63,7 +63,8 @@ class PapelGenericoModel extends \App\Models\BaseModel ]; - public function getIdFromCode(string $code=""){ + public function getIdFromCode(string $code = "") + { $builder = $this->db ->table($this->table . " t1") ->select( @@ -78,7 +79,8 @@ class PapelGenericoModel extends \App\Models\BaseModel } - public function getCodeFromId($id=0){ + public function getCodeFromId($id = 0) + { $builder = $this->db ->table($this->table . " t1") ->select( @@ -113,16 +115,16 @@ class PapelGenericoModel extends \App\Models\BaseModel 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(); + ->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(); } @@ -130,9 +132,9 @@ class PapelGenericoModel extends \App\Models\BaseModel { /* 1.-> Tipo impresion - 2.-> Maquina - 3.-> Papeles impresion asociados a esa maquina - 4.-> papeles genericos que aparecen en esos papeles 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") @@ -155,48 +157,48 @@ class PapelGenericoModel extends \App\Models\BaseModel ->where("t5.is_deleted", 0) ->where("t5.tipo", $tipo); - if($is_cubierta==true){ - - $builder->where("t2.cubierta", 1); - $builder->where("t5.uso", 'cubierta'); - } - - if($is_sobrecubierta==true){ - $builder->where("t2.sobrecubierta", 1); - $builder->where("t5.uso", 'sobrecubierta'); - } + if ($is_cubierta == true) { - if($is_cubierta==false && $is_sobrecubierta==false){ - $builder->where("t5.uso", 'interior'); - } + $builder->where("t2.cubierta", 1); + $builder->where("t5.uso", 'cubierta'); + } - if($is_guardas==true){ - $builder->where("t2.guardas", 1); - } + if ($is_sobrecubierta == true) { + $builder->where("t2.sobrecubierta", 1); + $builder->where("t5.uso", 'sobrecubierta'); + } - if($rotativa==true){ - $builder->where("t2.rotativa", 1); - } + if ($is_cubierta == false && $is_sobrecubierta == false) { + $builder->where("t5.uso", 'interior'); + } - if($mostrar_cliente!=null){ - $builder->where("t1.show_in_client", $mostrar_cliente); - } + if ($is_guardas == true) { + $builder->where("t2.guardas", 1); + } + + if ($rotativa == true) { + $builder->where("t2.rotativa", 1); + } + + if ($mostrar_cliente != null) { + $builder->where("t1.show_in_client", $mostrar_cliente); + } $data = $builder->orderBy("t1.nombre", "asc")->get()->getResultObject(); //var_dump($this->db->getLastQuery()); return $data; } - public function getGramajeComparador(string $papel_generico_nombre="", $uso="", $ejemplares=0) + public function getGramajeComparador(string $papel_generico_nombre = "", $uso = "", $ejemplares = 0) { - if($uso == 'cubierta' || $uso == 'sobrecubierta') + if ($uso == 'cubierta' || $uso == 'sobrecubierta') $tipo = 'colorhq'; else - $tipo=$uso; // color y colorhq valen para los dos - if($uso == 'bn') - $tipo="negro"; - if($uso == 'bnhq') - $tipo="negrohq"; + $tipo = $uso; // color y colorhq valen para los dos + if ($uso == 'bn') + $tipo = "negro"; + if ($uso == 'bnhq') + $tipo = "negrohq"; $builder = $this->db ->table($this->table . " t1") @@ -207,7 +209,7 @@ class PapelGenericoModel extends \App\Models\BaseModel ->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("t2.isActivo", 1) @@ -216,44 +218,43 @@ class PapelGenericoModel extends \App\Models\BaseModel ->where("t4.tipo", "impresion") ->where("t5.tipo", $tipo) ->where("t1.nombre", $papel_generico_nombre); - - $uso_tarifa = 'interior'; - if($uso == 'bn' || $uso == 'bnhq') - $builder->where("t2.bn", 1); - else if ($uso == 'color' || $uso == 'colorhq') - $builder->where("t2.color", 1); - else if ($uso == 'cubierta'){ - $uso_tarifa = 'cubierta'; - $builder->where("t2.cubierta", 1); - } - else if ($uso == 'sobrecubierta'){ - $uso_tarifa = 'sobrecubierta'; - $builder->where("t2.sobrecubierta", 1); - } + $uso_tarifa = 'interior'; - $builder->where("t5.uso", $uso_tarifa); + if ($uso == 'bn' || $uso == 'bnhq') + $builder->where("t2.bn", 1); + else if ($uso == 'color' || $uso == 'colorhq') + $builder->where("t2.color", 1); + else if ($uso == 'cubierta') { + $uso_tarifa = 'cubierta'; + $builder->where("t2.cubierta", 1); + } else if ($uso == 'sobrecubierta') { + $uso_tarifa = 'sobrecubierta'; + $builder->where("t2.sobrecubierta", 1); + } - $builder->where("t4.min <=", $ejemplares); - $builder->where("t4.max >=", $ejemplares); - - $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)); + $builder->where("t5.uso", $uso_tarifa); + + $builder->where("t4.min <=", $ejemplares); + $builder->where("t4.max >=", $ejemplares); + + $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)); } //tipo: negro, negrohq, color, colorhq //uso: interior, rotativa, cubierta, sobrecubierta - public function getGramajeLineasPresupuesto($papel_generico_id=0, $tipo="", $uso="") + public function getGramajeLineasPresupuesto($papel_generico_id = 0, $tipo = "", $uso = "") { $builder = $this->db ->table($this->table . " t1") @@ -264,7 +265,7 @@ class PapelGenericoModel extends \App\Models\BaseModel ->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("t2.isActivo", 1) @@ -274,42 +275,94 @@ class PapelGenericoModel extends \App\Models\BaseModel ->where("t5.tipo", $tipo) ->where("t1.id", $papel_generico_id); - $uso_tarifa = 'interior'; + $uso_tarifa = 'interior'; - if ($uso == 'cubierta'){ - $uso_tarifa = 'cubierta'; - $builder->where("t2.cubierta", 1); - } - else if ($uso == 'sobrecubierta'){ - $uso_tarifa = 'sobrecubierta'; - $builder->where("t2.sobrecubierta", 1); - } - else{ - if($tipo == 'negro' || $tipo == 'negrohq') - $builder->where("t2.bn", 1); - else if ($tipo == 'color' || $tipo == 'colorhq') - $builder->where("t2.color", 1); - } - - if($uso=='rotativa') - $builder->where("t2.rotativa", 1); - else - $builder->where("t2.rotativa", 0); + if ($uso == 'cubierta') { + $uso_tarifa = 'cubierta'; + $builder->where("t2.cubierta", 1); + } else if ($uso == 'sobrecubierta') { + $uso_tarifa = 'sobrecubierta'; + $builder->where("t2.sobrecubierta", 1); + } else { + if ($tipo == 'negro' || $tipo == 'negrohq') + $builder->where("t2.bn", 1); + else if ($tipo == 'color' || $tipo == 'colorhq') + $builder->where("t2.color", 1); + } - $builder->where("t5.uso", $uso_tarifa); - - - $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)); + if ($uso == 'rotativa') + $builder->where("t2.rotativa", 1); + else + $builder->where("t2.rotativa", 0); + + $builder->where("t5.uso", $uso_tarifa); + + + $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)); } + + + public function getPapelGenericoCliente($tipo, $is_cubierta = false, $papel_especial = false) + { + /* + 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.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") + ->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.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('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(); + + if ($is_cubierta == true) { + + $builder->where("t2.cubierta", 1); + $builder->where("t5.uso", 'cubierta'); + } else { + $builder->where("t5.uso", 'interior'); + } + + if ($papel_especial == true) { + $builder->where("t1.show_in_client_special", 1); + } + + $data = $builder->orderBy("t1.nombre", "asc")->get()->getResultObject(); + //var_dump($this->db->getLastQuery()); + return $data; + } } diff --git a/ci4/app/Models/Configuracion/PapelImpresionModel.php b/ci4/app/Models/Configuracion/PapelImpresionModel.php index c2d5b91f..49db505f 100755 --- a/ci4/app/Models/Configuracion/PapelImpresionModel.php +++ b/ci4/app/Models/Configuracion/PapelImpresionModel.php @@ -145,7 +145,7 @@ class PapelImpresionModel extends \App\Models\BaseModel * * @return \CodeIgniter\Database\BaseBuilder */ - public function getResource(string $search = "", $generico_id=-1) + public function getResource(string $search = "", $generico_id = -1) { $builder = $this->db ->table($this->table . " t1") @@ -157,12 +157,12 @@ class PapelImpresionModel extends \App\Models\BaseModel t1.isActivo AS isActivo, t2.nombre AS papel_generico_id, t1.show_in_client AS show_in_client, t1.show_in_client_special AS show_in_client_special" ); - + $builder->join("lg_papel_generico t2", "t1.papel_generico_id = t2.id", "left"); $builder->where("t1.is_deleted", 0); $builder->where("t1.isActivo", 1); - if($generico_id>0){ - $builder->where("t1.papel_generico_id", $generico_id); + if ($generico_id > 0) { + $builder->where("t1.papel_generico_id", $generico_id); } return empty($search) @@ -182,29 +182,29 @@ class PapelImpresionModel extends \App\Models\BaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "'".$maquina_id."'". " as maquina_id, t1.id AS papel_impresion_id, '0' as active" + "'" . $maquina_id . "'" . " as maquina_id, t1.id AS papel_impresion_id, '0' as active" ); - + $builder->where("t1.is_deleted", 0); $builder->where("t1.isActivo", 1); $isFirst = true; $where_str = ""; //Si hay tarifas... - if (!empty($tarifas)){ - foreach ($tarifas as $tarifa){ + if (!empty($tarifas)) { + foreach ($tarifas as $tarifa) { if (!$isFirst) $where_str .= ' OR '; - else{ + else { $isFirst = false; } if ($tarifa->uso == 'cubierta') $where_str .= "`t1`.`cubierta`=1"; else if ($tarifa->uso == 'sobrecubierta') $where_str .= "`t1`.`sobrecubierta`=1"; - else{ + else { if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq') - $where_str .= "`t1`.`bn`=1 "; + $where_str .= "`t1`.`bn`=1 "; else $where_str .= "`t1`.`color`=1 "; } @@ -212,11 +212,11 @@ class PapelImpresionModel extends \App\Models\BaseModel $builder->where($where_str); } // si no hay tarifas no hay que devolver nada - else{ + else { // Se pone una condicion que no se puede dar $builder->where("t1.bn", 2); } - + return $builder; } @@ -229,43 +229,45 @@ class PapelImpresionModel extends \App\Models\BaseModel * * @return [type] */ - public function getIdPapelesImpresionForPresupuesto($papel_generico_id = null, $gramaje = null, $options=[]){ + public function getIdPapelesImpresionForPresupuesto($papel_generico_id = null, $gramaje = null, $options = []) + { $bn = array_key_exists('bn', $options) ? $options['bn'] : null; - $color = array_key_exists('color', $options)? $options['color'] : null; - $cubierta = array_key_exists('cubierta', $options)? $options['cubierta'] : null; - $sobrecubierta = array_key_exists('sobrecubierta', $options)? $options['sobrecubierta'] : null; - $guardas = array_key_exists('guardas', $options)? $options['guardas'] : null; - $rotativa = array_key_exists('rotativa', $options)? $options['rotativa'] : null; + $color = array_key_exists('color', $options) ? $options['color'] : null; + $cubierta = array_key_exists('cubierta', $options) ? $options['cubierta'] : null; + $sobrecubierta = array_key_exists('sobrecubierta', $options) ? $options['sobrecubierta'] : null; + $guardas = array_key_exists('guardas', $options) ? $options['guardas'] : null; + $rotativa = array_key_exists('rotativa', $options) ? $options['rotativa'] : null; $builder = $this->db ->table($this->table . " t1") ->distinct("t1.id") ->select( "t1.id AS id, t1.nombre AS nombre, t1.papel_generico_id AS papel_generico_id, - t1.gramaje as gramaje, t1.espesor AS espesor, t1.precio_tonelada AS precio_tonelada, t1.rotativa AS rotativa"); - + t1.gramaje as gramaje, t1.espesor AS espesor, t1.precio_tonelada AS precio_tonelada, t1.rotativa AS rotativa" + ); + $builder->where("t1.is_deleted", 0); $builder->where("t1.isActivo", 1); $builder->where("t1.papel_generico_id", $papel_generico_id); $builder->where("t1.gramaje", $gramaje); - - if(!is_null($bn)){ + + if (!is_null($bn)) { $builder->where("t1.bn", $bn); } - if(!is_null($color)){ + if (!is_null($color)) { $builder->where("t1.color", $color); } - if(!is_null($cubierta)){ + if (!is_null($cubierta)) { $builder->where("t1.cubierta", $cubierta); } - if(!is_null($sobrecubierta)){ + if (!is_null($sobrecubierta)) { $builder->where("t1.sobrecubierta", $sobrecubierta); } - if(!is_null($guardas)){ + if (!is_null($guardas)) { $builder->where("t1.guardas", $guardas); } - if(!is_null($rotativa)){ + if (!is_null($rotativa)) { $builder->where("t1.rotativa", $rotativa); } @@ -274,7 +276,8 @@ class PapelImpresionModel extends \App\Models\BaseModel //tipo: negro, negrohq, color, colorhq //uso: interior, rotativa, cubierta, sobrecubierta - public function getPapelesImpresionForMenu($papel_generico = null, $gramaje = null, $tipo = null, $uso=""){ + public function getPapelesImpresionForMenu($papel_generico = null, $gramaje = null, $tipo = null, $uso = "") + { $builder = $this->db ->table($this->table . " t1") ->distinct("t1.id") @@ -283,8 +286,9 @@ class PapelImpresionModel extends \App\Models\BaseModel ->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left") ->join("lg_maquinas_tarifas_impresion t5", "t4.id = t5.maquina_id", "left") ->select( - "t1.id AS id, t1.nombre AS text"); - + "t1.id AS id, t1.nombre AS text" + ); + $builder->where("t1.is_deleted", 0); $builder->where("t1.isActivo", 1); $builder->where("t2.is_deleted", 0); @@ -293,7 +297,7 @@ class PapelImpresionModel extends \App\Models\BaseModel $builder->where("t4.tipo", 'impresion'); $builder->where("t5.is_deleted", 0); $builder->where("t5.tipo", $tipo); - + $builder->where("t2.id", $papel_generico); $builder->where("t1.gramaje", $gramaje); @@ -303,32 +307,35 @@ class PapelImpresionModel extends \App\Models\BaseModel $builder->where("t1.sobrecubierta", 1); else if ($uso == 'guardas') $builder->where("t1.guardas", 1); - else{ - if($tipo == 'negro' || $tipo == 'negrohq') + else { + if ($tipo == 'negro' || $tipo == 'negrohq') $builder->where("t1.bn", 1); else if ($tipo == 'color' || $tipo == 'colorhq') $builder->where("t1.color", 1); } - if($uso=='rotativa') + if ($uso == 'rotativa') $builder->where("t1.rotativa", 1); else $builder->where("t1.rotativa", 0); - + return $builder->orderBy("t1.id", "asc")->get()->getResultObject(); } - public function getNombre($id){ + public function getNombre($id) + { $builder = $this->db ->table($this->table . " t1") ->select( - "t1.nombre AS text"); - + "t1.nombre AS text" + ); + $builder->where("t1.id", $id); return $builder->orderBy("t1.id", "asc")->get()->getResultObject(); } - public function getPapelGenericoCode($papel_id = 0){ + public function getPapelGenericoCode($papel_id = 0) + { $builder = $this->db ->table($this->table . " t1") ->select("t2.code AS code") @@ -337,12 +344,63 @@ class PapelImpresionModel extends \App\Models\BaseModel ->where("t1.is_deleted", 0) ->where("t1.isActivo", 1) ->where("t2.is_deleted", 0); - + $result = $builder->get()->getResultObject(); - if(count($result) > 0){ + if (count($result) > 0) { return $result[0]->code; - } - else + } else 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; + } } diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioInterior.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioInterior.php index 8d68314e..89d79925 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioInterior.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioInterior.php @@ -42,41 +42,13 @@ -
+

Papel interior

-
- " alt="offsetBlanco"> - -
- -
- " alt="offsetAhuesado"> - -
- -
- " alt="offsetAhuesadoVolumen"> - -
- -
- " alt="estucadoMate"> - -
-
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php index 88dcf6bd..2c305f2b 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php @@ -11,7 +11,7 @@ -
+
diff --git a/httpdocs/assets/js/safekat/common/common.js b/httpdocs/assets/js/safekat/common/common.js new file mode 100644 index 00000000..f6a9c187 --- /dev/null +++ b/httpdocs/assets/js/safekat/common/common.js @@ -0,0 +1,8 @@ +export function getToken() +{ + const scriptUrl = new URL(import.meta.url); + const params = new URLSearchParams(scriptUrl.search); + + const paramsObject = Object.fromEntries(params.entries()); + return paramsObject.token; +} diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js index e4b3812d..9eed8897 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js @@ -1,14 +1,22 @@ +import { getToken } from '../../common/common.js'; +import Ajax from '../../components/ajax.js'; + class DisenioInterior { constructor(domItem, wizardForm, validatorStepper) { + this.domItem = domItem; + this.csrf_token = getToken(); + this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); + this.wizardStep = wizardForm.querySelector('#interior-libro'); this.validatorStepper = validatorStepper; this.allowNext = true; this.disenioInterior = this.domItem.find(".disenio-interior"); this.divPapelInterior = this.domItem.find("#divPapelInterior"); + this.textoPapelInterior = this.domItem.find("#textoPapelInterior"); this.divPapelInteriorColor = this.domItem.find("#divPapelInteriorColor"); this.divGramajeInterior = this.domItem.find("#divGramajeInterior"); this.papelInterior = this.domItem.find(".papel-interior"); @@ -18,11 +26,6 @@ class DisenioInterior { this.colorEstandar = this.domItem.find("#colorEstandar"); this.colorPremium = this.domItem.find("#colorPremium"); - this.offsetBlanco = this.domItem.find("#offsetBlanco"); - this.offsetAhuesado = this.domItem.find("#offsetAhuesado"); - this.offsetAhuesadoVolumen = this.domItem.find("#offsetAhuesadoVolumen"); - this.estucadoMate = this.domItem.find("#estucadoMate"); - this.gramaje = this.domItem.find(".check-interior-gramaje"); this.gramaje70 = this.domItem.find("#interiorGramaje70"); this.gramaje80 = this.domItem.find("#interiorGramaje80"); @@ -41,11 +44,6 @@ class DisenioInterior { this.colorEstandar_color = this.domItem.find("#colorEstandarColor"); this.colorPremium_color = this.domItem.find("#colorPremiumColor"); - this.offsetBlanco_color = this.domItem.find("#offsetBlancoColor"); - this.offsetAhuesado_color = this.domItem.find("#offsetAhuesadoColor"); - this.offsetAhuesadoVolumen_color = this.domItem.find("#offsetAhuesadoVolumenColor"); - this.estucadoMate_color = this.domItem.find("#estucadoMateColor"); - this.gramaje_color = this.domItem.find(".check-interior-color-gramaje"); this.gramaje70_color = this.domItem.find("#interiorGramaje70Color"); this.gramaje80_color = this.domItem.find("#interiorGramaje80Color"); @@ -66,6 +64,7 @@ class DisenioInterior { this.initValidation(); + // Creamos un nuevo observador que detecta cambios en los atributos this.observer = new MutationObserver(mutations => { mutations.forEach(mutation => { @@ -87,7 +86,6 @@ class DisenioInterior { // Eventos this.disenioInterior.on('click', this.#handleDisenioInterior.bind(this)); - this.papelInterior.on('click', this.#handlePapelInterior.bind(this)); this.disenioInterior_color.on('click', this.#handleDisenioInterior.bind(this)); this.papelInterior_color.on('click', this.#handlePapelInterior.bind(this)); @@ -96,17 +94,9 @@ class DisenioInterior { this.observer.observe(this.negroPremium[0], { attributes: true }); this.observer.observe(this.colorEstandar[0], { attributes: true }); this.observer.observe(this.colorPremium[0], { attributes: true }); - this.observer.observe(this.offsetBlanco[0], { attributes: true }); - this.observer.observe(this.offsetAhuesado[0], { attributes: true }); - this.observer.observe(this.offsetAhuesadoVolumen[0], { attributes: true }); - this.observer.observe(this.estucadoMate[0], { attributes: true }); this.observer.observe(this.colorEstandar_color[0], { attributes: true }); this.observer.observe(this.colorPremium_color[0], { attributes: true }); - this.observer.observe(this.offsetBlanco_color[0], { attributes: true }); - this.observer.observe(this.offsetAhuesado_color[0], { attributes: true }); - this.observer.observe(this.offsetAhuesadoVolumen_color[0], { attributes: true }); - this.observer.observe(this.estucadoMate_color[0], { attributes: true }); - + this.checksGramaje.each(function () { const customOptionEL = $(this); @@ -114,10 +104,69 @@ class DisenioInterior { self.#handleClickGramaje(customOptionEL); }); }); - } + updatePapeles(papeles) { + + const context = this; + let tipo = 'negro'; + if (this.colorEstandar.hasClass('selected')) + tipo = 'color'; + else if (this.negroPremium.hasClass('selected')) + tipo = 'negrohq'; + else if (this.colorPremium.hasClass('selected')) + tipo = 'colorhq'; + + new Ajax('/papelesgenericos/getpapelgenericocliente', + { + [this.csrf_token]: this.csrf_hash, + tipo: tipo, + cubierta: 0, + }, + {}, + this.fillPapeles.bind(context), + (response) => { console.log(response); } + ).get(); + } + + fillPapeles(response) { + + + this.divPapelInterior.empty() + + if(response.papeles.length > 0){ + this.textoPapelInterior.removeClass('d-none'); + } + else{ + this.textoPapelInterior.addClass("d-none"); + } + + response.papeles.forEach(papel => { + var container = $('
', { + class: 'custom-selector d-flex flex-column align-items-center justify-content-center' + }); + + var radioButton = $('', { + type: 'radio', // Tipo de input + name: 'calcular-presupuesto papel-interior', + id: papel.id, // ID único + value: 'option1' // Valor del radio button + }); + + // Crear una etiqueta para el radio button + var label = $('