From 84693d5c6cb8a5e26675f22eb238abe73b4f6d20 Mon Sep 17 00:00:00 2001 From: Ignacio Martinez Navajas Date: Tue, 3 Jun 2025 11:24:44 +0200 Subject: [PATCH] Iniciada implementacion de recuperacion de historicos erp antiguo --- ci4/app/Config/Routes/CatalogoRoutes.php | 1 + .../Controllers/Catalogo/CatalogoLibros.php | 44 ++++++++++++-- .../Models/Presupuestos/ImportadorModel.php | 56 ++++++++++++------ .../vuexy/form/catalogo/_historicoPedidos.php | 58 +++++++++++++++++++ .../form/catalogo/viewCatalogoLibrosForm.php | 17 +++++- .../js/safekat/pages/catalogo/catalogo.js | 57 ++++++++++++++++++ 6 files changed, 208 insertions(+), 25 deletions(-) create mode 100644 ci4/app/Views/themes/vuexy/form/catalogo/_historicoPedidos.php diff --git a/ci4/app/Config/Routes/CatalogoRoutes.php b/ci4/app/Config/Routes/CatalogoRoutes.php index bbade431..143bd072 100644 --- a/ci4/app/Config/Routes/CatalogoRoutes.php +++ b/ci4/app/Config/Routes/CatalogoRoutes.php @@ -23,6 +23,7 @@ $routes->group('catalogo', ['namespace' => 'App\Controllers\Catalogo'], function * AJAX *========================**/ $routes->get('clientlist', 'CatalogoLibros::getClientList', ['as' => 'catalogoLibrosClientList']); + $routes->get('pedidosAntiguos', 'CatalogoLibros::datatablePedidosAntiguos', ['as' => 'catalogoLibrosPedidosAntiguosDT']); }); diff --git a/ci4/app/Controllers/Catalogo/CatalogoLibros.php b/ci4/app/Controllers/Catalogo/CatalogoLibros.php index e34d0c91..499e2275 100644 --- a/ci4/app/Controllers/Catalogo/CatalogoLibros.php +++ b/ci4/app/Controllers/Catalogo/CatalogoLibros.php @@ -5,6 +5,7 @@ use App\Controllers\BaseResourceController; use App\Entities\Catalogo\CatalogoLibroEntity; use App\Models\Catalogo\CatalogoLibroModel; use App\Models\Clientes\ClienteModel; +use App\Models\Presupuestos\ImportadorModel; use Hermawan\DataTables\DataTable; class CatalogoLibros extends BaseResourceController @@ -66,7 +67,7 @@ class CatalogoLibros extends BaseResourceController $sanitizedData = $this->sanitized($postData, true); $sanitizedData['user_created_id'] = auth()->user()->id; - unset($sanitizedData['iskn']); + unset($sanitizedData['iskn']); $noException = true; if ($successfulResult = $this->canValidate()): @@ -135,7 +136,7 @@ class CatalogoLibros extends BaseResourceController $sanitizedData['user_update_id'] = auth()->user()->id; $noException = true; - + if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) : @@ -173,7 +174,7 @@ class CatalogoLibros extends BaseResourceController 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'); @@ -224,7 +225,6 @@ class CatalogoLibros extends BaseResourceController } - /* IMN */ public function getClientList() { @@ -234,5 +234,41 @@ class CatalogoLibros extends BaseResourceController } + /* Historico de pedidos ERP antiguo */ + public function datatablePedidosAntiguos() + { + $reqData = $this->request->getGet(); + $start = $reqData['start'] ?? 0; + $length = $reqData['length'] ?? 10; + $catalogoId = $reqData['catalogo_id'] ?? null; + + // Instanciar el modelo directamente + $importadorModel = new ImportadorModel(); + + $q = $importadorModel->getHistoricoPedidosCatalogo($catalogoId); + + return DataTable::of($q) + ->setSearchableColumns([ + 't1.id', + 't1.created_at', + 't1.titulo', + 't1.paginas', + 't1.tirada', + 't1.total', + 't1.estado' + ]) + ->edit('total', fn($row) => number_format((float) $row->total, 2, ',', '.') . ' €') + ->edit('created_at', fn($row) => date('d/m/Y', strtotime($row->created_at))) + ->add('actionBtns', function ($row) { + return '
+ + Ver + +
'; + }, 'last') + ->toJson(returnAsObject: true); + } + + } diff --git a/ci4/app/Models/Presupuestos/ImportadorModel.php b/ci4/app/Models/Presupuestos/ImportadorModel.php index 10f79cf9..ba559de7 100755 --- a/ci4/app/Models/Presupuestos/ImportadorModel.php +++ b/ci4/app/Models/Presupuestos/ImportadorModel.php @@ -8,7 +8,8 @@ class ImportadorModel extends \App\Models\BaseModel protected $primaryKey = 'id'; protected $DBGroup = 'old_erp'; - public function getClientList(){ + public function getClientList() + { $db = \Config\Database::connect($this->DBGroup); // Conectar a olderp $builder = $db->table('customers'); @@ -19,8 +20,9 @@ class ImportadorModel extends \App\Models\BaseModel } - public function getPresupuestosList($clienteId, $search = ""){ - + public function getPresupuestosList($clienteId, $search = "") + { + $db = \Config\Database::connect($this->DBGroup); // Conectar a olderp $builder = $db->table('pedido_libro'); $builder->select('id as id, CONCAT(id, " - ", titulo) as name'); @@ -28,17 +30,18 @@ class ImportadorModel extends \App\Models\BaseModel $builder->whereIn('estado', ['finalizado', 'validado', 'presupuesto']); $builder->where('deleted_at', NULL); $builder->orderBy('updated_at', 'DESC'); - - return empty($search) ? - $builder->get()->getResultObject() : + + return empty($search) ? + $builder->get()->getResultObject() : $builder->groupStart()-> like('titulo', $search)-> - orLike('id', $search)-> + orLike('id', $search)-> groupEnd()->get()->getResultObject(); } - public function getPresupuestoForImport($id){ - + public function getPresupuestoForImport($id) + { + $db = \Config\Database::connect($this->DBGroup); // Conectar a olderp $builder = $db->table('pedido_libro t1') ->select('t1.paginas, t1.tirada, t1.papel_formato_personalizado, t1.customer_id, @@ -50,7 +53,7 @@ class ImportadorModel extends \App\Models\BaseModel ->where('t1.id', $id) ->where('t1.deleted_at', NULL); $query = $builder->get(); - $datosGenerales = $query->getRow(); + $datosGenerales = $query->getRow(); $builder = $db->table('pedido_libro_manipulado') ->select('nombre') @@ -69,10 +72,9 @@ class ImportadorModel extends \App\Models\BaseModel ->where('pedido_libro_id', $id) ->where('nombre', 'Prototipo'); $query = $builder->countAllResults(); - if($query > 0){ + if ($query > 0) { $datosGenerales->prototipo = 1; - } - else{ + } else { $datosGenerales->prototipo = 0; } @@ -85,7 +87,7 @@ class ImportadorModel extends \App\Models\BaseModel $query = $builder->get(); $lineas = $query->getResultObject(); - + return [ 'datosGenerales' => $datosGenerales, 'manipulados' => $manipulados, @@ -95,8 +97,9 @@ class ImportadorModel extends \App\Models\BaseModel } - public function getDatosGuardar($id){ - + public function getDatosGuardar($id) + { + $db = \Config\Database::connect($this->DBGroup); // Conectar a olderp $db = \Config\Database::connect($this->DBGroup); // Conectar a olderp $builder = $db->table('pedido_libro t1') @@ -107,12 +110,13 @@ class ImportadorModel extends \App\Models\BaseModel ->where('t1.id', $id) ->where('t1.deleted_at', NULL); $query = $builder->get(); - $datosGenerales = $query->getRow(); + $datosGenerales = $query->getRow(); return $query->getRow(); } - public function getDirecciones($id){ - + public function getDirecciones($id) + { + $db = \Config\Database::connect($this->DBGroup); // Conectar a olderp $builder = $db->table('pedido_libro_envios t1') ->select('t1.ejemplares as unidades, t1.att, t1.email, t1.direccion, t1.pais, @@ -123,6 +127,20 @@ class ImportadorModel extends \App\Models\BaseModel return $query->getResultObject(); } + public function getHistoricoPedidosCatalogo(?int $catalogoId = null) + { + $db = \Config\Database::connect($this->DBGroup); + + $builder = $db->table('pedido_libro t1') + ->select('t1.id, t1.created_at, t1.titulo, t1.paginas, t1.tirada, t1.total, t1.estado'); + + if ($catalogoId !== null) { + $builder->where('t1.catalogo_id', $catalogoId); + } + + return $builder; + } + } diff --git a/ci4/app/Views/themes/vuexy/form/catalogo/_historicoPedidos.php b/ci4/app/Views/themes/vuexy/form/catalogo/_historicoPedidos.php new file mode 100644 index 00000000..64e7776d --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/catalogo/_historicoPedidos.php @@ -0,0 +1,58 @@ +
+
+

+ +

+ +
+
+ + + + + + +
+
Pedidos - Antiguo ERP
+ + + + + + + + + + + + + +
IDFechaTítuloNº PáginasTiradaTotalEstadoAcciones
+
+
+
+
+
+ \ 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 index 2b520abb..c7f4d423 100644 --- a/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosForm.php +++ b/ci4/app/Views/themes/vuexy/form/catalogo/viewCatalogoLibrosForm.php @@ -1,3 +1,4 @@ +include('themes/_commonPartialsBs/datatables') ?> include("themes/_commonPartialsBs/select2bs5") ?> include("themes/_commonPartialsBs/sweetalert") ?> extend('themes/vuexy/main/defaultlayout') ?> @@ -19,6 +20,7 @@ + @@ -39,10 +41,21 @@ section('css') ?> - + endSection() ?> section("additionalExternalJs") ?> - + + + + + + + + endSection() ?> \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/catalogo/catalogo.js b/httpdocs/assets/js/safekat/pages/catalogo/catalogo.js index 9a9f1a58..e06e5e25 100644 --- a/httpdocs/assets/js/safekat/pages/catalogo/catalogo.js +++ b/httpdocs/assets/js/safekat/pages/catalogo/catalogo.js @@ -295,6 +295,7 @@ class Catalogo { this.selectGramajeSobrecubiertaPod.init(); this.acabadosSobrecubierta.init(); + this.initPedidosTable(); // Al cargar la página this.toggleSobrecubiertaFields(); @@ -327,6 +328,62 @@ class Catalogo { }); } + initPedidosTable() { + + const lastColPedidos = $('#tablaPedidosAntiguos').find("tr:first th").length - 1; + const catalogoId = $('#catalogo_id').val(); // Asegúrate que este valor exista + + const tablaPedidosAntiguos = $('#tablaPedidosAntiguos').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + orderCellsTop: true, + responsive: true, + scrollX: true, + lengthMenu: [5, 10, 25, 50, 75, 100], + pageLength: 10, + lengthChange: true, + dom: 'lfBrtip', + buttons: [ + 'copy', 'csv', 'excel', 'print', { + extend: 'pdfHtml5', + orientation: 'landscape', + pageSize: 'A4' + } + ], + order: [[1, 'desc']], + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + ajax: { + url: '/catalogo/libros/pedidosAntiguos', + method: 'GET', + data: { + catalogo_id: catalogoId + } + }, + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColPedidos] + } + ], + columns: [ + { data: 'id' }, + { data: 'created_at' }, + { data: 'titulo' }, + { data: 'paginas' }, + { data: 'tirada' }, + { data: 'total' }, + { data: 'estado' }, + { data: 'actionBtns' } + ] + }); + + + } + actualizarDesdeColor() { const total = parseInt(this.total.val(), 10) || 0; const color = parseInt(this.color.val(), 10) || 0;