From e2da90926dd8960c1771f59da054ba449956a991 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 13 Apr 2025 09:46:47 +0200 Subject: [PATCH] Listado de libros de catalogo --- ci4/app/Config/Routes/CatalogoRoutes.php | 19 ++ .../Controllers/Catalogo/CatalogoLibros.php | 289 ++++++++++++++++++ ...alogoLibro.php => CatalogoLibroEntity.php} | 2 +- ci4/app/Language/es/Catalogo.php | 92 ++++++ .../Models/Catalogo/CatalogoLibroModel.php | 8 +- .../catalogo/_catalogoLibrosFormItems.php | 74 +++++ .../form/catalogo/viewCatalogoLibrosForm.php | 26 ++ .../form/catalogo/viewCatalogoLibrosList.php | 68 +++++ .../themes/vuexy/main/menus/catalogo_menu.php | 9 +- .../assets/js/safekat/pages/catalogo/list.js | 98 ++++++ 10 files changed, 673 insertions(+), 12 deletions(-) create mode 100644 ci4/app/Config/Routes/CatalogoRoutes.php create mode 100644 ci4/app/Controllers/Catalogo/CatalogoLibros.php rename ci4/app/Entities/Catalogo/{CatalogoLibro.php => CatalogoLibroEntity.php} (98%) create mode 100644 ci4/app/Language/es/Catalogo.php create mode 100644 ci4/app/Views/themes/vuexy/form/catalogo/_catalogoLibrosFormItems.php create mode 100644 ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosForm.php create mode 100644 ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosList.php create mode 100644 httpdocs/assets/js/safekat/pages/catalogo/list.js diff --git a/ci4/app/Config/Routes/CatalogoRoutes.php b/ci4/app/Config/Routes/CatalogoRoutes.php new file mode 100644 index 00000000..db286b1e --- /dev/null +++ b/ci4/app/Config/Routes/CatalogoRoutes.php @@ -0,0 +1,19 @@ +group('catalogo', ['namespace' => 'App\Controllers\Catalogo'], function ($routes) { + /* Libros */ + $routes->group('libros', ['namespace' => 'App\Controllers\Catalogo'], function ($routes) { + $routes->get('', 'CatalogoLibros::index', ['as' => 'CatalogoLibrosList']); + $routes->get('gettarifas', 'CatalogoLibros::getSelect2'); + $routes->match(['get', 'post'], 'add', 'CatalogoLibros::add', ['as' => 'CatalogoLibrosAdd']); + $routes->match(['get', 'post'], 'edit/(:num)', 'CatalogoLibros::edit/$1', ['as' => 'CatalogoLibrosEdit']); + $routes->get('delete/(:num)', 'CatalogoLibros::delete/$1', ['as' => 'CatalogoLibrosDelete']); + $routes->get('datatable', 'CatalogoLibros::datatable', ['as' => 'CatalogoLibrosDT']); + $routes->get('select', 'CatalogoLibros::show_select', ["as" => "CatalogoLibrosShow"]); + }); +}); \ No newline at end of file diff --git a/ci4/app/Controllers/Catalogo/CatalogoLibros.php b/ci4/app/Controllers/Catalogo/CatalogoLibros.php new file mode 100644 index 00000000..54f7f2e2 --- /dev/null +++ b/ci4/app/Controllers/Catalogo/CatalogoLibros.php @@ -0,0 +1,289 @@ +viewData['pageTitle'] = lang('Catalogo.listingPage'); + $this->viewData['usingSweetAlert'] = true; + + // Breadcrumbs (IMN) + $this->viewData['breadcrumb'] = [ + ['title' => lang("App.menu_catalogo"), 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_catalogo_libros"), 'route' => route_to('CatalogoLibrosList'), 'active' => true] + ]; + + parent::initController($request, $response, $logger); + } + + + public function index() + { + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Catalogo.catalogo')]), + 'catalogoLibrosEntity' => new CatalogoLibroEntity(), + 'usingServerSideDataTable' => true, + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath . 'viewCatalogoLibrosList', $viewData); + } + + + public function add() + { + + if ($this->request->getPost()): + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, true); + + $noException = true; + if ($successfulResult = $this->canValidate()): + + + if ($this->canValidate()): + try { + $successfulResult = $this->model->skipValidation(true)->save($sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + endif; + + $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission + endif; + if ($noException && $successfulResult): + + $id = $this->model->db->insertID(); + + $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.'; + + if ($thenRedirect): + if (!empty($this->indexRoute)): + return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); + else: + return $this->redirect2listView('sweet-success', $message); + endif; + else: + $this->session->setFlashData('sweet-success', $message); + endif; + + endif; // $noException && $successfulResult + + endif; // ($requestMethod === 'post') + + $this->viewData['catalogoLibrosEntity'] = isset($sanitizedData) ? new CatalogoLibroEntity($sanitizedData) : new CatalogoLibroEntity(); + $this->viewData['formAction'] = route_to('createPais'); + $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Catalogo.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix'); + + + return $this->displayForm(__METHOD__); + } // end function add() + + public function edit($requestedId = null) + { + + if ($requestedId == null): + return $this->redirect2listView(); + endif; + $id = filter_var($requestedId, FILTER_SANITIZE_URL); + $catalogoLibrosEntity = $this->model->find($id); + + if ($catalogoLibrosEntity == false): + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Catalogo.pais')), $id]); + return $this->redirect2listView('sweet-error', $message); + endif; + + + + if ($this->request->getPost()): + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + if ($this->request->getPost('show_erp') == null) { + $sanitizedData['show_erp'] = false; + } + + + $noException = true; + if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + + if ($this->canValidate()): + try { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Catalogo.catalogo'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $catalogoLibrosEntity->fill($sanitizedData); + + $thenRedirect = false; + endif; + if ($noException && $successfulResult): + $id = $catalogoLibrosEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + if ($thenRedirect): + if (!empty($this->indexRoute)): + return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); + else: + return $this->redirect2listView('sweet-success', $message); + endif; + else: + $this->session->setFlashData('sweet-success', $message); + endif; + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $this->viewData['catalogoLibrosEntity'] = $catalogoLibrosEntity; + + $this->viewData['formAction'] = route_to('CatalogoLibrosEdit', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Catalogo.moduleTitle') . ' ' . lang('Basic.global.edit3'); + + + return $this->displayForm(__METHOD__, $id); + } // end function edit(...) + + + public function datatable() + { + $q = $this->model->getDatatableQuery(); + + $result = DataTable::of($q) + ->add("actionBtns", callback: function ($q) { + $actions = ''; + if (auth()->user()->can('catalogo.edit')) { + $actions .= ' +
+ +
'; + } + if (auth()->user()->can('catalogo.delete')) { + $actions .= ' +
+ +
'; + } + return $actions; + }); + + return $result->toJson(returnAsObject: true); + + } + + public function allItemsSelect() + { + if ($this->request->isAJAX()) { + $onlyActiveOnes = true; + $reqVal = $this->request->getPost('val') ?? 'id'; + $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false); + $nonItem = new \stdClass; + $nonItem->id = ''; + $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -'; + array_unshift($menu, $nonItem); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'menu' => $menu, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function menuItems() + { + if ($this->request->isAJAX()) { + $searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; + $reqId = goSanitize($this->request->getPost('id'))[0]; + $reqText = goSanitize($this->request->getPost('text'))[0]; + $onlyActiveOnes = false; + $columns2select = [$reqId ?? 'id', $reqText ?? 'nombre']; + $onlyActiveOnes = false; + $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); + $nonItem = new \stdClass; + $nonItem->id = ''; + $nonItem->text = '- ' . lang('Basic.global.None') . ' -'; + array_unshift($menu, $nonItem); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'menu' => $menu, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function menuItems2() + { + if ($this->request->isAJAX()) { + $query = $this->model->builder()->select( + [ + "id", + "nombre as name" + ] + )->orderBy("nombre", "asc"); + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("lg_paises.nombre", $this->request->getGet("q")) + ->groupEnd(); + } + + return $this->response->setJSON($query->get()->getResultObject()); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + +} diff --git a/ci4/app/Entities/Catalogo/CatalogoLibro.php b/ci4/app/Entities/Catalogo/CatalogoLibroEntity.php similarity index 98% rename from ci4/app/Entities/Catalogo/CatalogoLibro.php rename to ci4/app/Entities/Catalogo/CatalogoLibroEntity.php index 06b435c3..49a9cef2 100644 --- a/ci4/app/Entities/Catalogo/CatalogoLibro.php +++ b/ci4/app/Entities/Catalogo/CatalogoLibroEntity.php @@ -4,7 +4,7 @@ namespace App\Entities\Catalogo; use CodeIgniter\Entity\Entity; -class CatalogoLibro extends Entity +class CatalogoLibroEntity extends Entity { protected $attributes = [ 'id' => null, diff --git a/ci4/app/Language/es/Catalogo.php b/ci4/app/Language/es/Catalogo.php new file mode 100644 index 00000000..23e3d5b3 --- /dev/null +++ b/ci4/app/Language/es/Catalogo.php @@ -0,0 +1,92 @@ + 'Catálogo de libros', + 'listingPage' => 'Listado de libros', + 'catalogo' => 'catálogo', + 'libro' => 'libro', + 'id' => 'ID', + 'clienteId' => 'Cliente', + 'proveedorId' => 'Proveedor', + 'userCreatedId' => 'Usuario Creador', + 'userUpdateId' => 'Usuario Actualizador', + 'cubiertaArchivo' => 'Archivo de Cubierta', + 'cubiertaUrl' => 'URL de Cubierta', + 'ancho' => 'Ancho', + 'alto' => 'Alto', + 'peso' => 'Peso', + 'titulo' => 'Título', + 'autor' => 'Autor', + 'autorEntidad' => 'Entidad del Autor', + 'traductor' => 'Traductor', + 'ilustrador' => 'Ilustrador', + 'idioma' => 'Idioma', + 'numEdic' => 'Número de Edición', + 'fechaDisponibilidad' => 'Fecha de Disponibilidad', + 'fechaPublic' => 'Fecha de Publicación', + 'numFotos' => 'Número de Fotos', + 'numIlustr' => 'Número de Ilustraciones', + 'numIlustrColor' => 'Ilustraciones a Color', + 'numIlustrBn' => 'Ilustraciones en Blanco y Negro', + 'coleccion' => 'Colección', + 'isbn' => 'ISBN', + 'ean' => 'EAN', + 'editorial' => 'Editorial', + 'resumen' => 'Resumen', + 'resumenBreve' => 'Resumen Breve', + 'sello' => 'Sello', + 'paginas' => 'Páginas', + 'tipoImpresion' => 'Tipo de Impresión', + 'solapasAncho' => 'Ancho de Solapas', + 'cubiertasAncho' => 'Ancho de Cubiertas', + 'comentarios' => 'Comentarios', + 'negroPaginas' => 'Páginas Negras', + 'negroPapel' => 'Papel Negro', + 'negroGramaje' => 'Gramaje Negro', + 'colorPaginas' => 'Páginas a Color', + 'colorPapel' => 'Papel a Color', + 'colorGramaje' => 'Gramaje Color', + 'portadaPaginas' => 'Páginas de Portada', + 'portadaPapel' => 'Papel de Portada', + 'portadaGramaje' => 'Gramaje Portada', + 'portadaAcabado' => 'Acabado Portada', + 'cubiertaPaginas' => 'Páginas de Cubierta', + 'cubiertaPapel' => 'Papel de Cubierta', + 'cubiertaGramaje' => 'Gramaje Cubierta', + 'cubiertaAcabado' => 'Acabado Cubierta', + 'encuardenacion' => 'Encuadernación', + 'ubicacion' => 'Ubicación', + 'createdAt' => 'Fecha de Creación', + 'updatedAt' => 'Fecha de Actualización', + 'deletedAt' => 'Fecha de Eliminación', + + 'moduleTitle' => 'Catálogo de Libros', + 'catalogoLibro' => 'Libro', + 'catalogoLibroList' => 'Lista de Libros', + + 'validation' => [ + 'titulo' => [ + 'required' => 'El campo {field} es obligatorio.', + 'max_length' => 'El campo {field} no puede exceder {param} caracteres.', + ], + 'autor' => [ + 'required' => 'El campo {field} es obligatorio.', + ], + 'editorial' => [ + 'required' => 'El campo {field} es obligatorio.', + ], + 'coleccion' => [ + 'required' => 'El campo {field} es obligatorio.', + ], + 'paginas' => [ + 'required' => 'El campo {field} es obligatorio.', + 'integer' => 'El campo {field} debe ser un número entero.', + ], + 'ancho' => [ + 'required' => 'El campo {field} es obligatorio.', + ], + 'alto' => [ + 'required' => 'El campo {field} es obligatorio.', + ], + ], +]; diff --git a/ci4/app/Models/Catalogo/CatalogoLibroModel.php b/ci4/app/Models/Catalogo/CatalogoLibroModel.php index 6653b83d..6c6a8622 100644 --- a/ci4/app/Models/Catalogo/CatalogoLibroModel.php +++ b/ci4/app/Models/Catalogo/CatalogoLibroModel.php @@ -1,6 +1,6 @@ table($this->table . " t1") ->select( "t1.id AS id, - t1.nombre AS nombre, - t1.code AS cliente, t1.titulo AS titulo, - t1.edicion AS edicion, + t1.cliente_id AS cliente, + t1.titulo AS titulo, + t1.num_edic AS edicion, t1.autor AS autor, t1.isbn AS isbn, t1.ean AS ean, diff --git a/ci4/app/Views/themes/vuexy/form/catalogo/_catalogoLibrosFormItems.php b/ci4/app/Views/themes/vuexy/form/catalogo/_catalogoLibrosFormItems.php new file mode 100644 index 00000000..85fd9a00 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/catalogo/_catalogoLibrosFormItems.php @@ -0,0 +1,74 @@ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ +
+ +
\ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosForm.php b/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosForm.php new file mode 100644 index 00000000..00a34130 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosForm.php @@ -0,0 +1,26 @@ +include("themes/_commonPartialsBs/select2bs5") ?> +include("themes/_commonPartialsBs/sweetalert") ?> +extend('themes/vuexy/main/defaultlayout') ?> +section("content") ?> +
+
+
+
+

+
+
+ +
+ + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
+ +
+
+
+
+endSection() ?> diff --git a/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosList.php b/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosList.php new file mode 100644 index 00000000..69ff8f62 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosList.php @@ -0,0 +1,68 @@ +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/sweetalert') ?> +extend('themes/vuexy/main/defaultlayout') ?> + +section('content'); ?> +
+
+ +
+
+

+ 'btn btn-primary float-end']); ?> +
+
+ + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + + +section('css') ?> +"> + +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/main/menus/catalogo_menu.php b/ci4/app/Views/themes/vuexy/main/menus/catalogo_menu.php index 1a06ab34..1958e9aa 100644 --- a/ci4/app/Views/themes/vuexy/main/menus/catalogo_menu.php +++ b/ci4/app/Views/themes/vuexy/main/menus/catalogo_menu.php @@ -12,20 +12,15 @@ if (auth()->user()->inGroup('beta')) {