From 07cd952532fee52c440c7c7a70648ad0a52c19c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Mon, 16 Sep 2024 10:57:38 +0200 Subject: [PATCH] =?UTF-8?q?a=C3=B1adida=20la=20vista=20para=20modificar=20?= =?UTF-8?q?las=20direcciones=20de=20cliente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Config/Routes.php | 26 +- .../Clientes/Clientedirecciones.php | 87 +++++ ci4/app/Language/en/Clientes.php | 3 + ci4/app/Language/es/Clientes.php | 3 + .../clientes/cliente/_clienteFormItems.php | 2 +- .../viewClienteDireccionesList.php | 299 ++++++++++++++++++ .../themes/vuexy/main/menus/clientes_menu.php | 2 +- 7 files changed, 399 insertions(+), 23 deletions(-) create mode 100644 ci4/app/Views/themes/vuexy/form/clientes/direcciones/viewClienteDireccionesList.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index a44885c5..185309ad 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -365,30 +365,9 @@ $routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function $routes->post('menuitems', 'Cliente::menuItems', ['as' => 'menuItemsOfClientes']); }); - /* Precios */ - /*$routes->group('precios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { - $routes->post('datatable', 'ClientePrecios::datatable', ['as' => 'clientePreciosDT']); - $routes->post('datatable_editor', 'ClientePrecios::datatable_editor', ['as' => 'clientePreciosDTE']); - });*/ - - }); -/*$routes->group('cliente', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { - $routes->get('', 'Cliente::index', ['as' => 'clienteList']); - $routes->get('add', 'Cliente::add', ['as' => 'newCliente']); - $routes->post('add', 'Cliente::add', ['as' => 'createCliente']); - $routes->post('create', 'Cliente::create', ['as' => 'ajaxCreateCliente']); - $routes->put('(:num)/update', 'Cliente::update/$1', ['as' => 'ajaxUpdateCliente']); - $routes->post('edit/(:num)', 'Cliente::edit/$1', ['as' => 'updateCliente']); - $routes->get('delete/(:num)', 'Cliente::delete/$1', ['as' => 'deleteCliente']); - $routes->post('datatable', 'Cliente::datatable', ['as' => 'dataTableOfClientes']); - $routes->post('allmenuitems', 'Cliente::allItemsSelect', ['as' => 'select2ItemsOfClientes']); - -}); -$routes->resource('cliente', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Cliente', 'except' => 'show,new,create,update']);*/ - $routes->group('clienteprecios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->post('datatable', 'ClientePrecios::datatable', ['as' => 'dataTableOfClienteprecios']); $routes->post('datatable_editor', 'ClientePrecios::datatable_editor', ['as' => 'editorOfClienteprecios']); @@ -419,6 +398,11 @@ $routes->group('clienteusuarios', ['namespace' => 'App\Controllers\Clientes'], f }); +$routes->group('misdirecciones', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { + $routes->get('', 'Clientedirecciones::index', ['as' => 'clientedireccionesIndex']); +}); + + $routes->group('formas-pagos', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { $routes->get('', 'Formaspagos::index', ['as' => 'formaDePagoList']); $routes->get('add', 'Formaspagos::add', ['as' => 'newFormaDePago']); diff --git a/ci4/app/Controllers/Clientes/Clientedirecciones.php b/ci4/app/Controllers/Clientes/Clientedirecciones.php index 18385cf2..d37d665f 100755 --- a/ci4/app/Controllers/Clientes/Clientedirecciones.php +++ b/ci4/app/Controllers/Clientes/Clientedirecciones.php @@ -6,6 +6,8 @@ use App\Entities\Clientes\ClienteDireccionesEntity; use App\Models\Clientes\ClienteDireccionesModel; +use App\Models\Usuarios\UserModel; + use DataTables\Editor; use DataTables\Editor\Field; use DataTables\Editor\Validate; @@ -22,6 +24,53 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController protected static $controllerSlug = 'clientedirecciones'; + protected static $viewPath = 'themes/vuexy/form/clientes/direcciones/'; + + protected $indexRoute = 'clienteDireccionesList'; + + public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) + { + $this->viewData['pageTitle'] = lang('Clientes.direccionesEnvio'); + $this->viewData['usingSweetAlert'] = true; + + $this->viewData = ['usingServerSideDataTable' => true]; // JJO + + // Breadcrumbs (IMN) + $this->viewData['breadcrumb'] = [ + ['title' => lang("Clientes.direccionesEnvio"), 'route' => "javascript:void(0);", 'active' => false], + + ]; + + $this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null); + $this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteEntity->provincia_id ?? null); + $this->viewData['paisList'] = $this->getPaisListItems($clienteEntity->pais_id ?? null); + + parent::initController($request, $response, $logger); + } + + + public function index() + { + + $id = auth()->user()->id; + $user_model = new UserModel(); + $user = $user_model->find($id); + $cliente_id = $user->cliente_id; + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Clientes.cliente')]), + 'cliente_id' => $cliente_id, + "user_id" => $id, + 'usingServerSideDataTable' => true, + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath . 'viewClienteDireccionesList', $viewData); + } + public function add(){ if ($this->request->isAJAX()) { @@ -226,4 +275,42 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController return $this->failUnauthorized('Invalid request', 403); } } + + + protected function getPaisListItems($selId = null) + { + $paisModel = model('App\Models\Configuracion\PaisModel'); + $onlyActiveOnes = true; + $data = $paisModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes); + + return $data; + } + + protected function getComunidadAutonomaListItems($selId = null) + { + $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])]; + if (!is_null($selId)) : + $comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel'); + + $selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre'); + if (!empty($selOption)) : + $data[$selId] = $selOption[0]; + endif; + endif; + return $data; + } + + protected function getProvinciaListItems($selId = null) + { + $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])]; + if (!empty($selId)) : + $provinciaModel = model('App\Models\Configuracion\ProvinciaModel'); + + $selOption = $provinciaModel->where('id', $selId)->findColumn('nombre'); + if (!empty($selOption)) : + $data[$selId] = $selOption[0]; + endif; + endif; + return $data; + } } diff --git a/ci4/app/Language/en/Clientes.php b/ci4/app/Language/en/Clientes.php index c35ecd3e..de0cce45 100755 --- a/ci4/app/Language/en/Clientes.php +++ b/ci4/app/Language/en/Clientes.php @@ -54,6 +54,9 @@ return [ 'userCreatedId' => 'User Created ID', 'userUpdateId' => 'User Update ID', 'vencimiento' => 'Vencimiento', + + 'direccionesEnvio' => 'Shipping Addresses', + 'validation' => [ 'ccc' => [ 'max_length' => 'The {field} field cannot exceed {param} characters in length.', diff --git a/ci4/app/Language/es/Clientes.php b/ci4/app/Language/es/Clientes.php index ea299358..3e505bbb 100755 --- a/ci4/app/Language/es/Clientes.php +++ b/ci4/app/Language/es/Clientes.php @@ -46,6 +46,9 @@ return [ 'userCreatedId' => 'User Created ID', 'userUpdateId' => 'User Update ID', 'vencimiento' => 'Vencimiento', + + 'direccionesEnvio' => 'Direcciones de EnvĂ­o', + 'validation' => [ 'ccc' => [ 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php index 03ddbcd9..cc7dddde 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -1421,7 +1421,7 @@ $('#tableOfDireccionesEnvio').on( 'click', 'tbody span.edit-add', function (e) { $('#add_municipio').val(data.municipio) $('#add_provincia').val(data.provincia) $('#add_cp').val(data.cp) - $('#add_telefono').val(data.cp) + $('#add_telefono').val(data.telefono) var $newAddDialog = $("#addressForm") $newAddDialog.modal('show') diff --git a/ci4/app/Views/themes/vuexy/form/clientes/direcciones/viewClienteDireccionesList.php b/ci4/app/Views/themes/vuexy/form/clientes/direcciones/viewClienteDireccionesList.php new file mode 100644 index 00000000..cc8798e8 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/clientes/direcciones/viewClienteDireccionesList.php @@ -0,0 +1,299 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/vuexy/main/defaultlayout') ?> + +section('content'); ?> +
+
+
+
+

+
+
+ + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + + +section("additionalInlineJs") ?> +/**************************************** + Direcciones cliente +*****************************************/ +const actionBtns_add = function(data) { + return ` + + + + `; +}; + + +function saveAdd_callback(){ + if($('#addressForm').attr('action')=='create'){ + editorAddress + .create( false ) + .set( 'cliente_id', ) + .set( 'alias', $('#add_alias').val() ) + .set( 'att', $('#add_att').val() ) + .set( 'email', $('#add_email').val() ) + .set( 'direccion', $('#add_direccion').val() ) + .set( 'pais_id', $("#add_pais_id option:selected").val()) + .set( 'municipio', $('#add_municipio').val() ) + .set( 'provincia', $('#add_provincia').val() ) + .set( 'cp', $('#add_cp').val() ) + .set( 'telefono', $('#add_telefono').val() ) + .submit(); + } + else{ // edit + editorAddress + .edit( '#tableOfDireccionesEnvio tbody tr:eq('+$("#addressForm").attr('row-index')+ ')', false ) + .set( 'cliente_id', ) + .set( 'alias', $('#add_alias').val() ) + .set( 'att', $('#add_att').val() ) + .set( 'email', $('#add_email').val() ) + .set( 'direccion', $('#add_direccion').val() ) + .set( 'pais_id', $("#add_pais_id option:selected").val()) + .set( 'municipio', $('#add_municipio').val() ) + .set( 'provincia', $('#add_provincia').val() ) + .set( 'cp', $('#add_cp').val() ) + .set( 'telefono', $('#add_telefono').val() ) + .submit(); + + } +} + + +const editorAddress = new DataTable.Editor({ + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfDireccionesEnvio", + idSrc: 'id', + fields: [ { + name: "alias" + }, { + name: "att" + }, { + name: "email" + }, { + name: "direccion" + }, { + name: "municipio" + }, { + name: "provincia" + }, { + name: "pais_id" + }, { + name: "cp" + }, { + name: "telefono" + }, { + "name": "cliente_id", + "type": "hidden" + }, + ], + template: '#direccionesForm' +}); + +editorAddress.on( 'postSubmit', function ( e, json, data, action ) { + + yeniden(json.); + + $( ".error-text-form" ).remove(); + if('fieldErrors' in json){ + if(json.fieldErrors.length > 0){ + json.fieldErrors.forEach((error) => { + $('#add_' + error.name).after( + "

" + error.status + '

') + }) + } + } + else{ + $('#addressForm').modal("hide"); + } + +}) + +editorAddress.on( 'submitSuccess', function ( e, json, data, action ) { + + tableDirecciones.clearPipeline(); + tableDirecciones.draw(); +}); + +editorAddress.on( 'close', function ( e, json, data, action ) { + $('#tableOfDireccionesEnvio').DataTable().ajax.reload(); +}) + +const lastColNr2 = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1; + +var tableDirecciones = $('#tableOfDireccionesEnvio').DataTable( { + draw:2, + serverSide: true, + processing: true, + autoWidth: true, + responsive: true, + order: [0, "asc" ], + pageLength: 10, + lengthChange: false, + 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: function ( d ) { + d.cliente_id = ; + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + { 'data': 'alias' }, + { 'data': 'att' }, + { 'data': 'email' }, + { 'data': 'direccion' }, + { 'data': 'cp' }, + { 'data': 'municipio' }, + { 'data': 'provincia' }, + { 'data': 'pais_id' , + "render": function (data, type, row, meta) { + return row.pais; + }}, + { 'data': 'telefono' }, + { + data: actionBtns_add, + className: 'row-edit dt-center' + } + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr2] + }, + {"orderData": [ 0], "targets": 0 }, + + ], + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + text: "", + action: function ( e, dt, node, config ) { + $("#addressForm").attr('action','create') + var $newAddDialog = $("#addressForm") + $newAddDialog.modal('show') + } + } ] + } ); + + +$('#tableOfDireccionesEnvio').on( 'click', 'tbody span.edit-add', function (e) { + + const row = $(this).closest('tr'); + const data = tableDirecciones.row(row).data() + + $("#addressForm").attr('action','edit') + $("#addressForm").attr('row-index',row[0]._DT_RowIndex) + + $('#add_alias').val(data.alias) + $('#add_att').val(data.att) + $('#add_email').val(data.email) + $('#add_direccion').val(data.direccion) + $("#add_pais_id").val(data.pais_id).change() + $('#add_municipio').val(data.municipio) + $('#add_provincia').val(data.provincia) + $('#add_cp').val(data.cp) + $('#add_telefono').val(data.telefono) + + var $newAddDialog = $("#addressForm") + $newAddDialog.modal('show') +}) + +$(document).on('click', '.btn-delete-add', function(e) { + $(".btn-remove").attr('data-id', $(this).attr('data-id')); + $(".btn-remove").attr('table-id', '#tableOfDireccionesEnvio'); +}); + +function delete_direccion_envio(dataId){ + $.ajax({ + url: `/clientes/clientedirecciones/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + $('#confirm2delete').modal('toggle'); + tableDirecciones.clearPipeline(); + tableDirecciones.ajax.reload(); + popSuccessAlert(data.msg ?? jqXHR.statusText); + }).fail((jqXHR, textStatus, errorThrown) => { + popErrorAlert(jqXHR.responseJSON.messages.error) + }) +} + +$(document).on('click', '.btn-remove', function(e) { + + const dataId = $(this).attr('data-id'); + const tableId = $(this).attr('table-id'); + + if ($.isNumeric(dataId)) { + if(tableId=='#tableOfDireccionesEnvio') + delete_direccion_envio(dataId) + } +}); + + +endSection() ?> + + +section('css') ?> + + "> + "> +endSection() ?> + +section('additionalExternalJs') ?> + + + + + + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/main/menus/clientes_menu.php b/ci4/app/Views/themes/vuexy/main/menus/clientes_menu.php index fb8df9d1..71e53116 100644 --- a/ci4/app/Views/themes/vuexy/main/menus/clientes_menu.php +++ b/ci4/app/Views/themes/vuexy/main/menus/clientes_menu.php @@ -22,7 +22,7 @@ if (auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente user()->can('direcciones.menu')) { ?>