From e3182c77dce5ee0789d0ae831b19e197241c8b60 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Sun, 21 Apr 2024 20:16:03 +0200 Subject: [PATCH 1/2] Realizados arreglos para corregir bugs existentes (clientes y buscador de presupuestos --- ci4/app/Config/Routes.php | 3 +- .../Controllers/Clientes/Clientecontactos.php | 1 - ci4/app/Language/es/Presupuestos.php | 5 ++ .../clientes/cliente/_clienteFormItems.php | 82 +++++++------------ .../form/clientes/cliente/viewClienteForm.php | 2 +- .../buscador/viewBuscadorList.php | 26 ++++++ 6 files changed, 64 insertions(+), 55 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 09900984..270b9103 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -370,8 +370,8 @@ $routes->group('clienteprecios', ['namespace' => 'App\Controllers\Clientes'], fu $routes->post('datatable', 'Clienteprecios::datatable', ['as' => 'dataTableOfClienteprecios']); $routes->post('datatable_editor', 'Clienteprecios::datatable_editor', ['as' => 'editorOfClienteprecios']); }); -$routes->resource('clienteprecios', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Clienteprecios', 'except' => 'show,new,create,update']); +$routes->resource('clienteprecios', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Clienteprecios', 'except' => 'show,new,create,update']); $routes->group('clienteplantillaprecios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->get('', 'Clienteplantillaprecios::index', ['as' => 'clienteplantillapreciosList']); @@ -512,6 +512,7 @@ $routes->group('clientecontactos', ['namespace' => 'App\Controllers\Clientes'], $routes->post('(:num)/edit', 'Clientecontactos::edit/$1', ['as' => 'updateClienteContactos']); $routes->post('datatable', 'Clientecontactos::datatable', ['as' => 'dataTableOfClienteContactos']); $routes->post('datatable_editor', 'Clientecontactos::datatable_editor', ['as' => 'editorOfClienteContactos']); + $routes->get('delete/(:num)', 'Clientecontactos::delete/$1', ['as' => 'deleteClienteContactos']); $routes->post('allmenuitems', 'Clientecontactos::allItemsSelect', ['as' => 'select2ItemsOfClienteContactos']); $routes->post('menuitems', 'Clientecontactos::menuItems', ['as' => 'menuItemsOfClienteContactos']); }); diff --git a/ci4/app/Controllers/Clientes/Clientecontactos.php b/ci4/app/Controllers/Clientes/Clientecontactos.php index 3bc2f19a..7f425d01 100755 --- a/ci4/app/Controllers/Clientes/Clientecontactos.php +++ b/ci4/app/Controllers/Clientes/Clientecontactos.php @@ -60,7 +60,6 @@ class Clientecontactos extends \App\Controllers\GoBaseResourceController public function add() { - $requestMethod = $this->request->getMethod(); if ($requestMethod === 'post') : diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index 22a8ce5b..a9427ec2 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -24,6 +24,11 @@ return [ 'libroCosidoTapaDura' => "Cosido Tapa Dura", 'libroFresadoTapaBlanda' => "Fresado Tapa Blanda", 'libroFresadoTapaDura' => "Fresado Tapa Dura", + 'libroEspiralTapaDura' => "Espiral Tapa Dura", + 'libroEspiralTapaBlanda' => "Espiral Tapa Blanda", + 'libroWireoTapaDura' => "Wire-o Tapa Dura", + 'libroWireoTapaBlanda' => "Wire-o Tapa Blanda", + 'libroGrapado' => "Grapado", 'datosPresupuesto' => 'Datos generales del presupuesto', 'datosLibro' => 'Datos del libro', diff --git a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php index 66c48389..396da491 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -564,7 +564,6 @@ -
@@ -610,7 +609,6 @@
-
@@ -629,7 +627,6 @@
-
@@ -673,27 +670,6 @@ - - - - - -
- - -
- -*/ ?> - @@ -701,6 +677,12 @@ /**************************************** Funcionamiento general *****************************************/ +const url = window.location.href; +const url_parts = url.split('/'); +let id = -1; +if(url_parts[url_parts.length-2] == 'edit'){ + id = url_parts[url_parts.length-1]; +} $(document).on('click', '.btn-remove', function(e) { @@ -718,18 +700,21 @@ $(document).on('click', '.btn-remove', function(e) { } }); - endSection() ?> section("additionalInlineJs") ?> +/**************************************** + Contactos +*****************************************/ + const lastColNr = $('#tableOfClienteContactos').find("tr:first th").length - 1; const actionBtns = function(data) { return ` - + `; }; @@ -779,7 +764,6 @@ $(document).on('click', '.btn-remove', function(e) { editor.on( 'postSubmit', function ( e, json, data, action ) { - yeniden(json.); }); @@ -803,33 +787,27 @@ $(document).on('click', '.btn-remove', function(e) { ); } ); - // Delete row - $('#tableOfClienteContactos').on( 'click', 'tbody span.remove', function (e) { + $(document).on('click', '.btn-deleted', function(e) { + $(".btn-remove").attr('data-id', $(this).attr('data-id')); + }); - Swal.fire({ - title: '', - text: '', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - confirmButtonText: '', - cancelButtonText: '', - cancelButtonColor: '#d33' - }) - .then((result) => { - const dataId = $(this).data('id'); - const row = $(this).closest('tr'); - if (result.value) { - editor - .create( false ) - .edit( this.parentNode, false) - .set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') ) - .set( 'is_deleted', 1 ) - .submit(); - - } - }); + $(document).on('click', '.btn-remove', function(e) { + const dataId = $(this).attr('data-id'); + const row = $(this).closest('tr'); + if ($.isNumeric(dataId)) { + $.ajax({ + url: `/clientecontactos/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + $('#confirm2delete').modal('toggle'); + theTable.clearPipeline(); + theTable.row($(row)).invalidate().draw(); + popSuccessAlert(data.msg ?? jqXHR.statusText); + }).fail((jqXHR, textStatus, errorThrown) => { + popErrorAlert(jqXHR.responseJSON.messages.error) + }) + } }); var theTable = $('#tableOfClienteContactos').DataTable( { diff --git a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php index 6770633d..bfb3d633 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php @@ -49,7 +49,7 @@ $('#saveForm').click(); } } - }); + }); $('#soporteId').select2({ diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/buscador/viewBuscadorList.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/buscador/viewBuscadorList.php index d32bb435..1b5c671b 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/buscador/viewBuscadorList.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/buscador/viewBuscadorList.php @@ -121,6 +121,11 @@ $('#tableOfPresupuestos thead tr:eq(1) th').each(function (i) { selector.append(''); selector.append(''); selector.append(''); + selector.append(''); + selector.append(''); + selector.append(''); + selector.append(''); + selector.append(''); selector.on('change', function () { var val = $.fn.dataTable.util.escapeRegex( @@ -207,6 +212,27 @@ theTable = $('#tableOfPresupuestos').DataTable({ return ''; break; + + case "libroEspiralTapaDura": + return ''; + break; + + case "libroEspiralTapaBlanda": + return ''; + break; + + case "libroWireoTapaDura": + return ''; + break; + + case "libroWireoTapaBlanda": + return ''; + break; + + case "libroGrapado": + return ''; + break; + default: return data; // Debug break; From 9330b3a141f67bdef5e63abe20a5adbd7c35bc27 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Sun, 21 Apr 2024 21:26:41 +0200 Subject: [PATCH 2/2] Avance en usuarios de clientes --- ci4/app/Config/Routes.php | 4 + .../Controllers/Clientes/Clienteusuarios.php | 77 ++++++++++++ ci4/app/Language/es/App.php | 4 +- .../Models/Clientes/ClienteUsuariosModel.php | 110 ++++++++++++++++++ .../clientes/cliente/_clienteFormItems.php | 76 +++++++++++- .../form/clientes/cliente/viewClienteForm.php | 2 - 6 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 ci4/app/Controllers/Clientes/Clienteusuarios.php create mode 100644 ci4/app/Models/Clientes/ClienteUsuariosModel.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 270b9103..2ee527dd 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -391,6 +391,10 @@ $routes->group('clienteplantillaprecioslineas', ['namespace' => 'App\Controllers }); $routes->resource('clienteplantillaprecioslineas', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'clienteplantillaprecioslineas', 'except' => 'show,new,create,update']); +$routes->group('clienteusuarios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { + $routes->post('datatable', 'Clienteusuarios::datatable', ['as' => 'dataTableOfClienteUsuarios']); +}); + $routes->group('formas-pagos', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { $routes->get('', 'Formaspagos::index', ['as' => 'formaDePagoList']); diff --git a/ci4/app/Controllers/Clientes/Clienteusuarios.php b/ci4/app/Controllers/Clientes/Clienteusuarios.php new file mode 100644 index 00000000..1324b513 --- /dev/null +++ b/ci4/app/Controllers/Clientes/Clienteusuarios.php @@ -0,0 +1,77 @@ +viewData['pageTitle'] = lang('ClienteContactos.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + parent::initController($request, $response, $logger); + } + + + + public function datatable() + { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + if (!isset($reqData['draw']) || !isset($reqData['columns'])) { + $errstr = 'No data available in response to this specific request.'; + $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr); + return $response; + } + $start = $reqData['start'] ?? 0; + $length = $reqData['length'] ?? 5; + $search = $reqData['search']['value']; + $requestedOrder = $reqData['order']['0']['column'] ?? 1; + $order = ClienteUsuariosModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $id_C = $reqData['id_cliente'] ?? -1; + + $resourceData = $this->model->getResource("", $id_C)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $this->model->getResource()->countAllResults(), + $this->model->getResource("", $id_C)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + + +} diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index ed5cb4c1..653da4cf 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -130,8 +130,8 @@ return [ "profile_subtitle_tfa" => "Autenticación de dos factores (2FA)", "profile_first_name" => "Nombre", "profile_first_name_ph" => "Escriba su nombre", - "profile_last_name" => "Apellido", - "profile_last_name_ph" => "Escriba su apellido", + "profile_last_name" => "Apellidos", + "profile_last_name_ph" => "Escriba sus apellidos", "profile_email" => "Correo Electrónico", "profile_email_ph" => "Escriba su correo electrónico", "profile_mobile" => "Teléfono Móvil", diff --git a/ci4/app/Models/Clientes/ClienteUsuariosModel.php b/ci4/app/Models/Clientes/ClienteUsuariosModel.php new file mode 100644 index 00000000..6bec17a9 --- /dev/null +++ b/ci4/app/Models/Clientes/ClienteUsuariosModel.php @@ -0,0 +1,110 @@ + "t1.first_name", + 1 => "t1.last_name", + 2 => "t1.email", + ]; + + protected $allowedFields = ["id", "first_name", "last_name", "email"]; + protected $returnType = "App\Entities\Usuarios\UserEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + + protected $updatedField = "updated_at"; + + public static $labelField = "nombre"; + + protected $validationRules = [ + "last_name" => [ + "label" => "ClienteContactos.apellidos", + "rules" => "trim|max_length[500]", + ], + "email" => [ + "label" => "ClienteContactos.email", + "rules" => "trim|max_length[150]|valid_email|permit_empty", + ], + "first_name" => [ + "label" => "ClienteContactos.nombre", + "rules" => "trim|max_length[100]", + ], + ]; + + protected $validationMessages = [ + "last_name" => [ + "max_length" => "ClienteContactos.validation.apellidos.max_length", + ], + + "email" => [ + "max_length" => "ClienteContactos.validation.email.max_length", + "valid_email" => "ClienteContactos.validation.email.valid_email", + ], + "first_name" => [ + "max_length" => "ClienteContactos.validation.nombre.max_length", + ], + ]; + + public function findAllWithClientes(string $selcols = "*", int $limit = null, int $offset = 0) + { + $sql = + "SELECT t1." . + $selcols . + ", t2.nombre AS cliente_id FROM " . + $this->table . + " t1 LEFT JOIN clientes t2 ON t1.cliente_id = t2.id"; + if (!is_null($limit) && intval($limit) > 0) { + $sql .= " LIMIT " . $limit; + } + + if (!is_null($offset) && intval($offset) > 0) { + $sql .= " OFFSET " . $offset; + } + + $query = $this->db->query($sql); + $result = $query->getResultObject(); + return $result; + } + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource(string $search = "", $cliente_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id_user AS id, t1.first_name AS nombre, t1.last_name AS apellidos, t1.email AS email" + ); + + $builder->where('t1.id_user', $cliente_id); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.first_name", $search) + ->orLike("t1.last_name", $search) + ->orLike("t1.email", $search) + ->groupEnd(); + } +} diff --git a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php index 396da491..93a16106 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -659,7 +659,20 @@
-

Proximanente

+
+ + + + + + + + + + + + +
ID
@@ -1435,6 +1448,67 @@ function delete_direccion_envio(dataId){ endSection() ?> +section("additionalInlineJs") ?> +/**************************************** + Contactos +*****************************************/ + + const lastColNrCU = $('#tableOfClienteUsuarios').find("tr:first th").length - 1; + + var theTableCU = $('#tableOfClienteUsuarios').DataTable( { + serverSide: true, + processing: true, + autoWidth: true, + responsive: true, + lengthMenu: [ 5, 10, 25], + order: [[ 0, "asc" ], [ 1, "asc" ]], + pageLength: 10, + lengthChange: true, + searching: false, + paging: true, + info: false, + dom: '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>', + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + //id_cliente: id, + id_cliente: 1, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + { 'data': 'id' }, + { 'data': 'nombre' }, + { 'data': 'apellidos' }, + { 'data': 'email' }, + { + data: actionBtns, + className: 'row-edit dt-center' + } + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNrCU] + }, + { + "orderData": [ 0, 1 ], + "targets": 0 + }, + + ], + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + } + } ); + +endSection() ?> + + + section('css') ?> diff --git a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php index bfb3d633..09387422 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/viewClienteForm.php @@ -230,11 +230,9 @@ section('css') ?> - "> - endSection() ?>