From 033184cfa23e7eaf2a941ff204927782d90491c7 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 26 Apr 2025 16:52:59 +0200 Subject: [PATCH 1/9] Iniciando herramienta de importacion desde catalogo --- ci4/app/Config/Routes/ImportadoresRoutes.php | 29 +++ ci4/app/Controllers/Catalogo/notas.txt | 2 - .../Importadores/ImportadorCatalogo.php | 188 ++++++++++++++++++ 3 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 ci4/app/Config/Routes/ImportadoresRoutes.php delete mode 100644 ci4/app/Controllers/Catalogo/notas.txt create mode 100644 ci4/app/Controllers/Importadores/ImportadorCatalogo.php diff --git a/ci4/app/Config/Routes/ImportadoresRoutes.php b/ci4/app/Config/Routes/ImportadoresRoutes.php new file mode 100644 index 00000000..5e3f03c5 --- /dev/null +++ b/ci4/app/Config/Routes/ImportadoresRoutes.php @@ -0,0 +1,29 @@ +group('importador', ['namespace' => 'App\Controllers\Importadores'], function ($routes) { + /* Libros */ + $routes->group('catalogo', ['namespace' => 'App\Controllers\Importadores'], function ($routes) { + /**====================== + * CRUD + *========================**/ + $routes->get('', 'ImportadorCatalogo::index', ['as' => 'importadorCatalogoTool']); + $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']); + + + /**====================== + * AJAX + *========================**/ + $routes->get('clientlist', 'CatalogoLibros::getClientList', ['as' => 'catalogoLibrosClientList']); + + + }); +}); \ No newline at end of file diff --git a/ci4/app/Controllers/Catalogo/notas.txt b/ci4/app/Controllers/Catalogo/notas.txt deleted file mode 100644 index 3d18002e..00000000 --- a/ci4/app/Controllers/Catalogo/notas.txt +++ /dev/null @@ -1,2 +0,0 @@ -Portada Id Cliente Título Edición Autor Archivo ISBN EAN Páginas Acciones -Lo que hay que listar \ No newline at end of file diff --git a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php new file mode 100644 index 00000000..04f3e51b --- /dev/null +++ b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php @@ -0,0 +1,188 @@ +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); + + $sanitizedData['user_created_id'] = auth()->user()->id; + unset($sanitizedData['isk']); + + $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('catalogoLibrosAdd'); + $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()): + + $postData = $this->request->getPost(); + $sanitizedData = $this->sanitized($postData, true); + unset($sanitizedData['isk']); + $sanitizedData['user_update_id'] = auth()->user()->id; + + $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(...) + + + +} From 9375b9b6249931c9846115606bdbe6079cea56a8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 26 Apr 2025 21:22:39 +0200 Subject: [PATCH 2/9] =?UTF-8?q?A=C3=B1adiendo=20idiomas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Importadores/ImportadorCatalogo.php | 6 +- ci4/app/Language/es/Importador.php | 75 +++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 ci4/app/Language/es/Importador.php diff --git a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php index 04f3e51b..354c8362 100644 --- a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php +++ b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php @@ -27,13 +27,13 @@ class ImportadorCatalogo extends BaseResourceController public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { - $this->viewData['pageTitle'] = lang('Catalogo.listingPage'); + $this->viewData['pageTitle'] = lang('Importador.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] + ['title' => lang("App.menu_importador"), 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_importador_catalogo"), 'route' => route_to('importadorCatalogoTool'), 'active' => true] ]; parent::initController($request, $response, $logger); diff --git a/ci4/app/Language/es/Importador.php b/ci4/app/Language/es/Importador.php new file mode 100644 index 00000000..cc6ae34e --- /dev/null +++ b/ci4/app/Language/es/Importador.php @@ -0,0 +1,75 @@ + 'Catálogo de libros', + 'listingPage' => 'Listado de libros', + 'catalogo' => 'catálogo', + 'libro' => 'libro', + 'id' => 'ID', + 'clienteId' => 'Cliente', + 'cliente' => 'Cliente', + 'proveedorId' => 'Proveedor', + 'userCreatedId' => 'Usuario Creador', + 'userUpdateId' => 'Usuario Actualizador', + 'cubiertaArchivo' => 'Archivo de Cubierta', + 'cubiertaUrl' => 'URL de Cubierta', + 'portada' => 'Portada', + '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', + 'edicion' => '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', + 'seleccionarTipoImpresion' => 'Seleccionar 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', + + 'catalogoLibro' => 'Libro', + 'catalogoLibroList' => 'Lista de Libros', + 'datosGenerales' => 'Datos generales del libro', + 'otrosDatosLibro' => 'Otros datos del libro', + 'configuracionLibro' => 'Configuración del libro', + 'ficherosLibro' => 'Ficheros', + 'created_by_at' => 'Creado:', + 'updated_by_at' => 'Actualizado:', +]; From b50e564641542ab1eeae3d3372d6b134f54722a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 26 Apr 2025 21:32:22 +0200 Subject: [PATCH 3/9] Desplegando arcihvos iniciales --- ci4/app/Config/RBAC.zip | Bin 282 -> 0 bytes ci4/app/Config/Routes/ImportadoresRoutes.php | 6 --- .../themes/vuexy/form/importador/.delete | 0 .../catalogo/viewImportadorCatalogoTool.php | 51 ++++++++++++++++++ 4 files changed, 51 insertions(+), 6 deletions(-) delete mode 100644 ci4/app/Config/RBAC.zip create mode 100644 ci4/app/Views/themes/vuexy/form/importador/.delete create mode 100644 ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php diff --git a/ci4/app/Config/RBAC.zip b/ci4/app/Config/RBAC.zip deleted file mode 100644 index 7c497e7997358182e56ddc487cf1fc9d43a7af34..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 282 zcmWIWW@Zs#0D(6i)1$x)D8UM(gPa_l^#g!PxWIzwN_b&P^wKj+vQtwF0=yZS>=|&G zrvf!u07`>R=VDL*a~T;V7@W%VV&t~mW`xSaDTuMS+yFBcWR5ZrgN=o`h&ba}*+6zN N0pT_v?FZs8006k8AM5}C diff --git a/ci4/app/Config/Routes/ImportadoresRoutes.php b/ci4/app/Config/Routes/ImportadoresRoutes.php index 5e3f03c5..5bf2caca 100644 --- a/ci4/app/Config/Routes/ImportadoresRoutes.php +++ b/ci4/app/Config/Routes/ImportadoresRoutes.php @@ -12,17 +12,11 @@ $routes->group('importador', ['namespace' => 'App\Controllers\Importadores'], fu * CRUD *========================**/ $routes->get('', 'ImportadorCatalogo::index', ['as' => 'importadorCatalogoTool']); - $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']); /**====================== * AJAX *========================**/ - $routes->get('clientlist', 'CatalogoLibros::getClientList', ['as' => 'catalogoLibrosClientList']); }); diff --git a/ci4/app/Views/themes/vuexy/form/importador/.delete b/ci4/app/Views/themes/vuexy/form/importador/.delete new file mode 100644 index 00000000..e69de29b diff --git a/ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php b/ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php new file mode 100644 index 00000000..190b62f4 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php @@ -0,0 +1,51 @@ +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 From b0ac132e594b533a4df9c9278eb3425c967cd4f5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 26 Apr 2025 23:05:15 +0200 Subject: [PATCH 4/9] Arreglado bug en archivo de migrate del catalogo --- ...2025-04-22-204851_CreateCatalogoLibros.php | 131 ++++++++++-------- 1 file changed, 70 insertions(+), 61 deletions(-) diff --git a/ci4/app/Database/Migrations/2025-04-22-204851_CreateCatalogoLibros.php b/ci4/app/Database/Migrations/2025-04-22-204851_CreateCatalogoLibros.php index d61b9c81..ca18132f 100644 --- a/ci4/app/Database/Migrations/2025-04-22-204851_CreateCatalogoLibros.php +++ b/ci4/app/Database/Migrations/2025-04-22-204851_CreateCatalogoLibros.php @@ -11,69 +11,78 @@ class CreateCatalogoLibros extends Migration $this->db->query('SET foreign_key_checks = 0'); $this->forge->addField([ - 'id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'auto_increment' => true], - 'cliente_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'proveedor_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'user_created_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'default' => 1], - 'user_update_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'default' => 1], - 'cubierta_archivo' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'cubierta_url' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true], - 'ancho' => ['type' => 'DOUBLE', 'constraint' => '8,2'], - 'alto' => ['type' => 'DOUBLE', 'constraint' => '8,2'], - 'peso' => ['type' => 'DOUBLE', 'constraint' => '8,2', 'null' => true], - 'titulo' => ['type' => 'VARCHAR', 'constraint' => 300], - 'autor' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'autor_entidad' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'traductor' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'ilustrador' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'idioma' => ['type' => 'VARCHAR', 'constraint' => 3, 'default' => 'spa'], - 'num_edic' => ['type' => 'INT', 'default' => 1, 'null' => true], - 'fecha_disponibilidad' => ['type' => 'DATE', 'null' => true], - 'fecha_public' => ['type' => 'DATE', 'null' => true], - 'num_fotos' => ['type' => 'INT', 'default' => 0], - 'num_ilustr' => ['type' => 'INT', 'default' => 0], - 'num_ilustr_color' => ['type' => 'INT', 'default' => 0], - 'num_ilustr_bn' => ['type' => 'INT', 'default' => 0], - 'coleccion' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'isk' => ['type' => 'VARCHAR', 'constraint' => 64, 'null' => true], - 'isbn' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'ean' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'editorial' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'resumen' => ['type' => 'TEXT', 'null' => true], - 'resumen_breve' => ['type' => 'TEXT', 'null' => true], - 'sello' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'paginas' => ['type' => 'INT'], - 'tipo_impresion' => ['type' => 'ENUM', 'constraint' => ['negro','negrohq','color','colorhq'], 'null' => true], - 'comentarios' => ['type' => 'TEXT', 'null' => true], - 'negro_paginas' => ['type' => 'INT', 'null' => true], - 'negro_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'negro_gramaje' => ['type' => 'DOUBLE', 'null' => true], - 'negro_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'negro_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], - 'color_paginas' => ['type' => 'INT', 'null' => true], - 'color_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'color_gramaje' => ['type' => 'DOUBLE', 'null' => true], - 'color_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'color_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], - 'cubierta_paginas' => ['type' => 'INT', 'null' => true], - 'cubierta_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'cubierta_gramaje' => ['type' => 'DOUBLE', 'null' => true], - 'cubierta_acabado_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'cubierta_ancho_solapas' => ['type' => 'DOUBLE', 'constraint' => '8,2', 'default' => 0.00, 'unsigned' => true], - 'cubierta_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'cubierta_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], - 'sobrecubierta_paginas' => ['type' => 'INT', 'null' => true], - 'sobrecubierta_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'sobrecubierta_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'auto_increment' => true], + 'cliente_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'proveedor_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'user_created_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'default' => 1], + 'user_update_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'default' => 1], + 'cubierta_archivo' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'cubierta_url' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true], + 'ancho' => ['type' => 'DOUBLE', 'constraint' => '8,2'], + 'alto' => ['type' => 'DOUBLE', 'constraint' => '8,2'], + 'peso' => ['type' => 'DOUBLE', 'constraint' => '8,2', 'null' => true], + 'titulo' => ['type' => 'VARCHAR', 'constraint' => 300], + 'autor' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'autor_entidad' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'traductor' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'ilustrador' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'idioma' => ['type' => 'VARCHAR', 'constraint' => 3, 'default' => 'spa'], + 'num_edic' => ['type' => 'INT', 'default' => 1, 'null' => true], + 'fecha_disponibilidad' => ['type' => 'DATE', 'null' => true], + 'fecha_public' => ['type' => 'DATE', 'null' => true], + 'num_fotos' => ['type' => 'INT', 'default' => 0], + 'num_ilustr' => ['type' => 'INT', 'default' => 0], + 'num_ilustr_color' => ['type' => 'INT', 'default' => 0], + 'num_ilustr_bn' => ['type' => 'INT', 'default' => 0], + 'coleccion' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'isk' => ['type' => 'VARCHAR', 'constraint' => 64, 'null' => true], + 'isbn' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'ean' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'editorial' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'resumen' => ['type' => 'TEXT', 'null' => true], + 'resumen_breve' => ['type' => 'TEXT', 'null' => true], + 'sello' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'paginas' => ['type' => 'INT'], + 'tipo_impresion' => ['type' => 'ENUM', 'constraint' => ['negro', 'negrohq', 'color', 'colorhq'], 'null' => true], + 'comentarios' => ['type' => 'TEXT', 'null' => true], + 'negro_paginas' => ['type' => 'INT', 'null' => true], + 'negro_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'negro_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'negro_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'negro_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'color_paginas' => ['type' => 'INT', 'null' => true], + 'color_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'color_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'color_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'color_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'cubierta_paginas' => ['type' => 'INT', 'null' => true], + 'cubierta_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'cubierta_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'cubierta_acabado_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'cubierta_ancho_solapas' => ['type' => 'DOUBLE', 'constraint' => '8,2', 'default' => 0.00, 'unsigned' => true], + 'cubierta_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'cubierta_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'sobrecubierta_paginas' => ['type' => 'INT', 'null' => true], + 'sobrecubierta_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'sobrecubierta_gramaje' => ['type' => 'DOUBLE', 'null' => true], 'sobrecubierta_acabado_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], 'sobrecubierta_ancho_solapas' => ['type' => 'DOUBLE', 'constraint' => '8,2', 'default' => 0.00, 'unsigned' => true], - 'sobrecubierta_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'sobrecubierta_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], - 'encuadernacion_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], - 'ubicacion' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'created_at' => ['type' => 'TIMESTAMP', 'default' => 'CURRENT_TIMESTAMP'], - 'updated_at' => ['type' => 'TIMESTAMP', 'null' => true], - 'deleted_at' => ['type' => 'TIMESTAMP', 'null' => true], + 'sobrecubierta_pod_papel_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'sobrecubierta_pod_gramaje' => ['type' => 'DOUBLE', 'null' => true], + 'encuadernacion_id' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => true], + 'ubicacion' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'created_at' => [ + 'type' => 'TIMESTAMP', + 'default' => new \CodeIgniter\Database\RawSql('CURRENT_TIMESTAMP'), + ], + 'updated_at' => [ + 'type' => 'TIMESTAMP', + 'null' => true, + ], + 'deleted_at' => [ + 'type' => 'TIMESTAMP', + 'null' => true, + ], ]); $this->forge->addKey('id', true); From e8958dc8938f6060cbb105c3ad981d452d7753f0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 26 Apr 2025 23:23:04 +0200 Subject: [PATCH 5/9] Implementado menu lateral --- .../Importadores/ImportadorCatalogo.php | 6 ++--- ci4/app/Language/en/App.php | 2 +- ci4/app/Language/es/App.php | 3 ++- ci4/app/Language/es/Importador.php | 2 +- ci4/app/Language/es/RolesPermisos.php | 5 ++++ .../catalogo/viewImportadorCatalogoTool.php | 3 +-- .../themes/vuexy/main/menu_impresion.php | 2 +- .../vuexy/main/menus/importacion_menu.php | 15 ----------- .../vuexy/main/menus/importadores_menu.php | 27 +++++++++++++++++++ 9 files changed, 41 insertions(+), 24 deletions(-) delete mode 100755 ci4/app/Views/themes/vuexy/main/menus/importacion_menu.php create mode 100644 ci4/app/Views/themes/vuexy/main/menus/importadores_menu.php diff --git a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php index 354c8362..221a0bd0 100644 --- a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php +++ b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php @@ -32,8 +32,8 @@ class ImportadorCatalogo extends BaseResourceController // Breadcrumbs (IMN) $this->viewData['breadcrumb'] = [ - ['title' => lang("App.menu_importador"), 'route' => "javascript:void(0);", 'active' => false], - ['title' => lang("App.menu_importador_catalogo"), 'route' => route_to('importadorCatalogoTool'), 'active' => true] + ['title' => lang("App.menu_importadores"), 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_importadores_catalogo"), 'route' => route_to('importadorCatalogoTool'), 'active' => true] ]; parent::initController($request, $response, $logger); @@ -53,7 +53,7 @@ class ImportadorCatalogo extends BaseResourceController $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class - return view(static::$viewPath . 'viewCatalogoLibrosList', $viewData); + return view(static::$viewPath . 'viewImportadorCatalogoTool', $viewData); } diff --git a/ci4/app/Language/en/App.php b/ci4/app/Language/en/App.php index be8505b2..a839dc44 100755 --- a/ci4/app/Language/en/App.php +++ b/ci4/app/Language/en/App.php @@ -699,7 +699,7 @@ return [ "menu_digitalizacion" => "Digitalisation", - "menu_importacion" => "Import", + "menu_importadores" => "Import", "menu_catalogo" => "Catalogue", "menu_catalogo_libros" => "Books", diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index cddbcfc2..eda99a6e 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -719,7 +719,8 @@ return [ "menu_digitalizacion" => "Digitalización", - "menu_importacion" => "Importación", + "menu_importadores" => "Importadores", + "menu_importadores_catalogo" => "Desde catálogo", "menu_catalogo" => "Catálogo", "menu_catalogo_libros" => "Libros", diff --git a/ci4/app/Language/es/Importador.php b/ci4/app/Language/es/Importador.php index cc6ae34e..b8982f34 100644 --- a/ci4/app/Language/es/Importador.php +++ b/ci4/app/Language/es/Importador.php @@ -1,7 +1,7 @@ 'Catálogo de libros', + 'moduleTitle' => 'Importador desde catálogo', 'listingPage' => 'Listado de libros', 'catalogo' => 'catálogo', 'libro' => 'libro', diff --git a/ci4/app/Language/es/RolesPermisos.php b/ci4/app/Language/es/RolesPermisos.php index 0bcc7616..ce946f1e 100755 --- a/ci4/app/Language/es/RolesPermisos.php +++ b/ci4/app/Language/es/RolesPermisos.php @@ -67,6 +67,11 @@ return [ 'vencimientosPermission' => 'Vencimientos', "ticketsSection" => "Tickets", 'produccionSection' => 'Producción', + 'catalogoSection' => 'Catálogo', + 'importadoresSection' => 'Importadores', + 'catalogoPermission' => 'Desde catálogo', + + 'validation' => [ 'id' => [ diff --git a/ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php b/ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php index 190b62f4..1c3174aa 100644 --- a/ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php +++ b/ci4/app/Views/themes/vuexy/form/importador/catalogo/viewImportadorCatalogoTool.php @@ -8,8 +8,7 @@
-

- 'btn btn-primary float-end']); ?> +

diff --git a/ci4/app/Views/themes/vuexy/main/menu_impresion.php b/ci4/app/Views/themes/vuexy/main/menu_impresion.php index 64464e5c..97d53883 100755 --- a/ci4/app/Views/themes/vuexy/main/menu_impresion.php +++ b/ci4/app/Views/themes/vuexy/main/menu_impresion.php @@ -32,7 +32,7 @@ require "menus/maquinista_menu.php"; - require "menus/importacion_menu.php"; + require "menus/importadores_menu.php"; require "menus/catalogo_menu.php"; diff --git a/ci4/app/Views/themes/vuexy/main/menus/importacion_menu.php b/ci4/app/Views/themes/vuexy/main/menus/importacion_menu.php deleted file mode 100755 index f3d1a48b..00000000 --- a/ci4/app/Views/themes/vuexy/main/menus/importacion_menu.php +++ /dev/null @@ -1,15 +0,0 @@ -user()->inGroup('beta')) { -?> - - - \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/main/menus/importadores_menu.php b/ci4/app/Views/themes/vuexy/main/menus/importadores_menu.php new file mode 100644 index 00000000..8abad150 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/main/menus/importadores_menu.php @@ -0,0 +1,27 @@ +user()->can('importadores.menu')) { + ?> + + + + + \ No newline at end of file From ae456c88900e04bce090bc86f250f9d7202cef3f Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 27 Apr 2025 00:00:58 +0200 Subject: [PATCH 6/9] Implementado script principal --- .../Importadores/ImportadorCatalogo.php | 2 +- .../catalogo/viewImportadorCatalogoTool.php | 28 ++++++- .../js/safekat/pages/importadores/.delete | 0 .../importadores/catalogo/catalogo_tool.js | 74 +++++++++++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 httpdocs/assets/js/safekat/pages/importadores/.delete create mode 100644 httpdocs/assets/js/safekat/pages/importadores/catalogo/catalogo_tool.js diff --git a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php index 221a0bd0..1fe91a85 100644 --- a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php +++ b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php @@ -1,5 +1,5 @@
-

+

- + +
+ +
+ + + + + + + + + + + + + + + +
cnt_pedidaprecio_compraidlineainputdescripcionAcción
+ +
+ + +
+ +
+ endSection() ?> diff --git a/httpdocs/assets/js/safekat/pages/importadores/catalogo/catalogo_tool.js b/httpdocs/assets/js/safekat/pages/importadores/catalogo/catalogo_tool.js index e72a8bfb..8fce7010 100644 --- a/httpdocs/assets/js/safekat/pages/importadores/catalogo/catalogo_tool.js +++ b/httpdocs/assets/js/safekat/pages/importadores/catalogo/catalogo_tool.js @@ -2,13 +2,21 @@ import Ajax from '../../../components/ajax.js'; document.addEventListener('DOMContentLoaded', function () { - // Columnas que espera la tabla (en el orden de HTML) const TABLE_COLUMNS = ["input", "idlinea", "descripcion", "cnt_pedida", "precio_compra"]; - let dataTable; // referencia al DataTable + let dataTable; dataTable = $('#excelTable').DataTable({ orderCellsTop: true, - fixedHeader: true + responsive: true, + scrollX: true, + lengthMenu: [5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500], + pageLength: 25, + lengthChange: true, + dom: 'lfrtip', + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + order: [[1, 'asc']] }); document.getElementById('excelFile').addEventListener('change', function (e) { @@ -28,124 +36,156 @@ document.addEventListener('DOMContentLoaded', function () { reader.readAsArrayBuffer(file); }); - function validateAndLoadDataTable(data) { + async function validateAndLoadDataTable(data) { if (data.length === 0) return; const headers = data[0].map(h => h.toString().trim()); - - // Crear un índice rápido de nombreColumna => posicion const headerMap = {}; headers.forEach((name, idx) => { - headerMap[name.toLowerCase()] = idx; // pasar todo a minúsculas para evitar errores + headerMap[name.toLowerCase()] = idx; }); - // Verificar si todas las columnas requeridas existen const missing = TABLE_COLUMNS.filter(col => !(col in headerMap)); if (missing.length > 0) { Swal.fire({ title: 'Error', - text: 'Faltan las siguientes columnas en el Excel: ' + missing.join(', '), + text: 'Faltan las siguientes columnas: ' + missing.join(', '), icon: 'error', confirmButtonText: 'Aceptar', buttonsStyling: true, - customClass: { - confirmButton: 'btn btn-danger' - } + customClass: { confirmButton: 'btn btn-danger' } }); - dataTable.clear().draw(); // limpia tabla + dataTable.clear().draw(); return; } const rows = []; for (let i = 1; i < data.length; i++) { - const row = []; + const rowData = TABLE_COLUMNS.map(col => data[i][headerMap[col]] ?? ''); - TABLE_COLUMNS.forEach(col => { - const idx = headerMap[col]; - row.push(data[i][idx] ?? ''); - }); + // Llamar backend para validar la fila + const isValid = await validarFila(rowData); - // Agregar botón al final - row.push(''); + let checkboxHtml = ''; + let actionBtnsHtml = ''; - rows.push(row); + if (isValid) { + checkboxHtml = ``; + + actionBtnsHtml = ` +
+ + +
+ `; + } else { + checkboxHtml = ``; + + actionBtnsHtml = ` +
+ No Apto + +
+ `; + } + + rows.push([checkboxHtml, ...rowData, actionBtnsHtml]); } dataTable.clear().rows.add(rows).draw(); - // Agregar eventos dinámicos para eliminar + setupEventListeners(); + } + + async function validarFila(rowData) { + try { + const response = await fetch('/importador/catalogo/validar-fila', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRF-TOKEN': '' + }, + body: JSON.stringify({ fila: rowData }) + }); + + const result = await response.json(); + return result.apto === true; + } catch (error) { + console.error('Error validando fila', error); + return false; + } + } + + function setupEventListeners() { $('#excelTable tbody').off('click', '.deleteRow').on('click', '.deleteRow', function () { dataTable.row($(this).parents('tr')).remove().draw(); }); + + $('#excelTable tbody').off('click', '.importRow').on('click', '.importRow', function () { + const rowData = dataTable.row($(this).parents('tr')).data(); + console.log('Importar esta fila:', rowData); + // Aquí podrías enviar sólo esta fila al servidor si quieres importar individualmente + }); } - $('#excelTable thead tr:eq(1) th').each(function (i) { - const title = $(this).text(); - - if (title.trim() !== '') { // Solo si el th tiene título - $(this).html(''); - - $('input', this).on('keyup change', function () { - if (dataTable.column(i).search() !== this.value) { - dataTable - .column(i) - .search(this.value) - .draw(); - } - }); - } - }); - document.getElementById('importBtn').addEventListener('click', function () { - const allData = dataTable.rows().data().toArray(); - const rowsToSend = allData.map(row => row.slice(0, -1)); // sin botón - - if (rowsToSend.length === 0) { + const selectedRows = []; + + dataTable.rows().every(function () { + const data = this.data(); + const checkboxHtml = $(data[0]).find('input.select-row'); + if (checkboxHtml.length > 0 && checkboxHtml.is(':checked') && !checkboxHtml.is(':disabled')) { + selectedRows.push(data.slice(1, -1)); // sin checkbox ni botones + } + }); + + if (selectedRows.length === 0) { Swal.fire({ title: 'Atención', - text: 'No hay datos para importar.', + text: 'No hay filas aptas seleccionadas para importar.', icon: 'warning', confirmButtonText: 'Aceptar', buttonsStyling: true, - customClass: { - confirmButton: 'btn btn-warning' - } + customClass: { confirmButton: 'btn btn-warning' } }); return; } - + fetch('/importar', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '' }, - body: JSON.stringify({ data: rowsToSend }) + body: JSON.stringify({ data: selectedRows }) }).then(res => res.json()) - .then(response => { - Swal.fire({ - title: 'Importación exitosa', - text: response.message, - icon: 'success', - confirmButtonText: 'Aceptar', - buttonsStyling: true, - customClass: { - confirmButton: 'btn btn-success' - } - }); - }) - .catch(error => { - console.error(error); - Swal.fire({ - title: 'Error', - text: 'Hubo un problema al importar los datos.', - icon: 'error', - confirmButtonText: 'Aceptar', - buttonsStyling: true, - customClass: { - confirmButton: 'btn btn-danger' - } - }); - }); + .then(response => { + Swal.fire({ + title: 'Importación exitosa', + text: response.message, + icon: 'success', + confirmButtonText: 'Aceptar', + buttonsStyling: true, + customClass: { confirmButton: 'btn btn-success' } + }); + }) + .catch(error => { + console.error(error); + Swal.fire({ + title: 'Error', + text: 'Error importando datos.', + icon: 'error', + confirmButtonText: 'Aceptar', + buttonsStyling: true, + customClass: { confirmButton: 'btn btn-danger' } + }); + }); }); -}); \ No newline at end of file + +});