diff --git a/ci4/app/Config/RBAC/permissionMatrix.php b/ci4/app/Config/RBAC/permissionMatrix.php index 19be9092..63f2d991 100644 --- a/ci4/app/Config/RBAC/permissionMatrix.php +++ b/ci4/app/Config/RBAC/permissionMatrix.php @@ -41,22 +41,17 @@ const SK_PERMISSION_MATRIX = [ "tarifa-acabado.edit", "tarifa-acabado.delete", "tarifa-acabado.menu", - "servicio-acabado.create", - "servicio-acabado.edit", - "servicio-acabado.delete", - "servicio-acabado.menu", "tarifa-encuadernacion.create", "tarifa-encuadernacion.edit", "tarifa-encuadernacion.delete", "tarifa-encuadernacion.menu", - "tarifa-extra.create", - "tarifa-extra.edit", - "tarifa-extra.delete", - "tarifa-extra.menu", "tarifa-envio.create", "tarifa-envio.edit", "tarifa-envio.delete", "tarifa-envio.menu", + "servicio-acabado.create", + "servicio-acabado.delete", + "servicio-acabado.menu", "proveedores.create", "proveedores.edit", "proveedores.delete", diff --git a/ci4/app/Config/RBAC/permissions.php b/ci4/app/Config/RBAC/permissions.php index cb3aecac..ac95e36a 100644 --- a/ci4/app/Config/RBAC/permissions.php +++ b/ci4/app/Config/RBAC/permissions.php @@ -41,10 +41,6 @@ const SK_PERMISSIONS = [ 'tarifa-acabado.edit' => 'Can edit', 'tarifa-acabado.delete' => 'Can delete', 'tarifa-acabado.menu' => 'Menu shall be visualize', - 'servicio-acabado.create' => 'Can create', - 'servicio-acabado.edit' => 'Can edit', - 'servicio-acabado.delete' => 'Can delete', - 'servicio-acabado.menu' => 'Menu shall be visualize', 'tarifa-encuadernacion.create' => 'Can create', 'tarifa-encuadernacion.edit' => 'Can edit', 'tarifa-encuadernacion.delete' => 'Can delete', @@ -57,6 +53,10 @@ const SK_PERMISSIONS = [ 'tarifa-envio.edit' => 'Can edit', 'tarifa-envio.delete' => 'Can delete', 'tarifa-envio.menu' => 'Menu shall be visualize', + 'servicio-acabado.create' => 'Can create', + 'servicio-acabado.edit' => 'Can edit', + 'servicio-acabado.delete' => 'Can delete', + 'servicio-acabado.menu' => 'Menu shall be visualize', 'proveedores.create' => 'Can create', 'proveedores.edit' => 'Can edit', 'proveedores.delete' => 'Can delete', diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 39e25423..4aff5c7d 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -215,8 +215,9 @@ $routes->group('serviciosacabado', ['namespace' => 'App\Controllers\Tarifas\Acab $routes->post('add', 'ServiciosAcabado::add', ['as' => 'createServicioAcabado']); $routes->get('edit/(:num)', 'ServiciosAcabado::edit/$1', ['as' => 'editServicioAcabado']); $routes->post('edit/(:num)', 'ServiciosAcabado::edit/$1', ['as' => 'updateServicioAcabado']); - $routes->post('edit/(:num)', 'ServiciosAcabado::edit/$1', ['as' => 'updateServicioAcabado']); $routes->get('datatable', 'ServiciosAcabado::datatable'); + $routes->get('getselectedtarifas', 'ServiciosAcabado::getTarifasSeleccionadas'); + $routes->get('gettarifas', 'ServiciosAcabado::getTarifas'); }); $routes->resource('tarifasmanipulado', ['namespace' => 'App\Controllers\Tarifas\Acabados', 'controller' => 'ServiciosAcabado', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 32085f3f..6fdfd9fa 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -1128,18 +1128,21 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $solapas = $this->request->getGet('solapas') ?? 0; $lomo = $this->request->getGet('lomo') ?? 0; - $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; - $tipo = $this->request->getGet("tipo"); $uso = $this->request->getGet("uso") ?? 'interior'; + + $anchoLibro = $ancho; + $cubierta = false; if ($uso == 'cubierta') { $cubierta = true; + $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; } $sobrecubierta = false; if ($uso == 'sobrecubierta') { $sobrecubierta = true; + $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; } $guardas = false; if ($uso == 'guardas') { @@ -1191,7 +1194,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $solapas = $this->request->getGet('solapas') ?? 0; $lomo = $this->request->getGet('lomo') ?? 0; - $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; + $anchoLibro = $ancho; $tipo_impresion_id = $this->request->getGet("tipo_impresion"); $tapa_dura = model('App\Models\Configuracion\TipoPresupuestoModel')->get_isTapaDura(intval($tipo_impresion_id)); @@ -1202,10 +1205,12 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $cubierta = false; if ($uso == 'cubierta') { $cubierta = true; + $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; } $sobrecubierta = false; if ($uso == 'sobrecubierta') { $sobrecubierta = true; + $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; } $guardas = false; if ($uso == 'guardas') { diff --git a/ci4/app/Controllers/Tarifas/Acabados/ServiciosAcabado.php b/ci4/app/Controllers/Tarifas/Acabados/ServiciosAcabado.php index 1aed73dc..903c75fe 100644 --- a/ci4/app/Controllers/Tarifas/Acabados/ServiciosAcabado.php +++ b/ci4/app/Controllers/Tarifas/Acabados/ServiciosAcabado.php @@ -15,13 +15,13 @@ class ServiciosAcabado extends BaseResourceController protected $format = 'json'; protected static $singularObjectName = 'Servicio Acabado'; - protected static $singularObjectNameCc = 'servicioAcabado'; + protected static $singularObjectNameCc = 'serviciosAcabado'; protected static $pluralObjectName = 'Servicios Acabado'; protected static $pluralObjectNameCc = 'serviciosAcabado'; protected static $controllerSlug = 'serviciosacabado'; - protected static $viewPath = 'themes/vuexy/form/tarifas/acabado/'; + protected static $viewPath = 'themes/vuexy/form/tarifas/acabado/'; protected $indexRoute = 'serviciosAcabadoList'; @@ -31,12 +31,7 @@ class ServiciosAcabado extends BaseResourceController $this->viewData['pageTitle'] = lang('Servicioacabado.moduleTitle'); $this->viewData['usingSweetAlert'] = true; - // Se indica que este controlador trabaja con soft_delete - $this->soft_delete = true; - // Se indica el flag para los ficheros borrados - $this->delete_flag = 1; - - //$this->viewData = ['usingServerSideDataTable' => true]; + $this->viewData = ['usingServerSideDataTable' => true]; // Breadcrumbs $this->viewData['breadcrumb'] = [ @@ -66,18 +61,162 @@ class ServiciosAcabado extends BaseResourceController return view(static::$viewPath . 'viewServiciosAcabadoList', $viewData); } - public function datatable(){ - + + public function edit($requestedId = null) + { + + checkPermission('tarifa-acabado.edit', $this->indexRoute); + + if ($requestedId == null): + return $this->redirect2listView(); + endif; + $id = filter_var($requestedId, FILTER_SANITIZE_URL); + $servicio = $this->model->find($id); + + if ($servicio == false): + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('ServicioAcabado.servicioacabado')), $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); + + $sanitizedData['user_updated_id'] = auth()->user()->id; + + if ($this->request->getPost('mostrar_en_presupuesto_cliente') == null) { + $sanitizedData['mostrar_en_presupuesto'] = false; + } + + if ($this->request->getPost('acabado_cubierta') == null) { + $sanitizedData['acabado_cubierta'] = false; + } + + if ($this->request->getPost('acabado_sobrecubierta') == null) { + $sanitizedData['acabado_sobrecubierta'] = 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('Tarifaacabado.tarifaacabado'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $servicio->fill($sanitizedData); + + $thenRedirect = false; + endif; + + if ($noException && $successfulResult): + $id = $servicio->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['servicio'] = $servicio; + $this->viewData['tarifasSeleccionadas'] = [1,2]; + + $this->viewData['formAction'] = route_to('updateServicioAcabado', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('ServicioAcabado.moduleTitle') . ' ' . lang('Basic.global.edit3'); + + + return $this->displayForm(__METHOD__, $id); + } // end function edit(...) + + + public function datatable() + { + $model = model(ServicioAcabadoModel::class); $q = $model->getDatatableQuery(); //return $this->response->setJSON($q->get()); return DataTable::of($q) - ->add("action", fn($q) => $q->id) + ->add("action", callback: function ($q) { + return '' + . (auth()->user()->can("servicio-acabado.delete") ? + '' + : ''); + }) ->edit( "updated_at", - fn($q) => Time::createFromFormat("Y-m-d H:i:s",$q->updated_at)->format("d/m/Y") - ) + fn($q) => Time::createFromFormat("Y-m-d H:i:s", $q->updated_at)->format("d/m/Y") + ) ->toJson(returnAsObject: true); } + public function getTarifasSeleccionadas() + { + $model = model("App\Models\Tarifas\Acabados\TarifaAcabadoModel"); + $ids = $this->request->getGet('ids'); + + if (empty($ids)) { + return $this->response->setJSON([]); + } + + $query = $model->select('lg_tarifa_acabado.id, lg_tarifa_acabado.nombre')->whereIn('lg_tarifa_acabado.id', $ids); + + $query->where('lg_tarifa_acabado.deleted_at', null); + + $tarifas = $query->findAll(); + + return $this->response->setJSON($tarifas); + } + + public function getTarifas() + { + $model = model("App\Models\Tarifas\Acabados\TarifaAcabadoModel"); + + $search = $this->request->getGet('search'); // Obtiene el parámetro de búsqueda + + $acabado_cubierta = $this->request->getGet('acabado_cubierta'); + $acabado_sobrecubierta = $this->request->getGet('acabado_sobrecubierta'); + + $query = $model->select('lg_tarifa_acabado.id, lg_tarifa_acabado.nombre'); + + if (!empty($search)) { + $query->like('lg_tarifa_acabado.nombre', $search); + } + + if($acabado_cubierta){ + $query->where('lg_tarifa_acabado.acabado_cubierta', $acabado_cubierta); + } + if($acabado_sobrecubierta){ + $query->where('lg_tarifa_acabado.acabado_sobrecubierta', $acabado_sobrecubierta); + } + + $query->where('lg_tarifa_acabado.deleted_at', null); + + $tarifas = $query->findAll(); + + return $this->response->setJSON($tarifas); + } + } \ No newline at end of file diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index bb2ea491..2ec21cca 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -797,7 +797,7 @@ return [ "menu_tarifamanipulado" => "Manipulado", "menu_tarifaencuadernacion" => "Encuadernación", "menu_tarifapapelcompra" => "Papel compra", - "menu_serviciosAcabado" => "Servicios acabado", + "menu_Servicioacabado" => "Servicios acabado", "menu_tarifaacabado" => "Acabado", "menu_tarifapapeldefecto" => "Papel defecto", "menu_tarifaenvio" => "Envío", diff --git a/ci4/app/Views/themes/vuexy/form/tarifas/acabado/viewServiciosAcabadoForm.php b/ci4/app/Views/themes/vuexy/form/tarifas/acabado/viewServiciosAcabadoForm.php new file mode 100644 index 00000000..4d829cba --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/tarifas/acabado/viewServiciosAcabadoForm.php @@ -0,0 +1,100 @@ +include("themes/_commonPartialsBs/select2bs5") ?> +include("themes/_commonPartialsBs/sweetalert") ?> +extend('themes/vuexy/main/defaultlayout') ?> + +section("content") ?> +
+
+
+
+

+
+
+ + + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> +
+
+
+ + +
+ +
+ Seleccione si es servicio cubierta o sobrecubierta (o ambos) antes de + seleccionar las tarifas asociadas. Al cambiar estas opciones, se borrará la + selección. +
+
+ +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ + +
+
+ + +
+ + +
+ + +
+ +
+ +
+ user()->can('tarifa-acabado.edit')): ?> + " /> + + "btn btn-secondary float-start"]) ?> +
+
+
+
+
+ +endSection() ?> + +section('additionalExternalJs') ?> + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/tarifas/acabado/viewServiciosAcabadoList.php b/ci4/app/Views/themes/vuexy/form/tarifas/acabado/viewServiciosAcabadoList.php index c3c82a3d..c8860f11 100644 --- a/ci4/app/Views/themes/vuexy/form/tarifas/acabado/viewServiciosAcabadoList.php +++ b/ci4/app/Views/themes/vuexy/form/tarifas/acabado/viewServiciosAcabadoList.php @@ -8,7 +8,9 @@

- 'btn btn-primary float-end']); ?> + user()->can('servicio-acabado.create')): ?> + 'btn btn-primary float-end']); ?> +
diff --git a/httpdocs/assets/js/safekat/pages/tarifas/serviciosAcabado/edit.js b/httpdocs/assets/js/safekat/pages/tarifas/serviciosAcabado/edit.js new file mode 100644 index 00000000..8fb8a4e5 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/tarifas/serviciosAcabado/edit.js @@ -0,0 +1,78 @@ +import Ajax from '../../../components/ajax.js'; + + +class editServiciosAcabado { + + constructor() { + + this.selectElement = $('#tarifas'); + this.acabado_cubierta = $('#acabado_cubierta'); + this.acabado_sobrecubierta = $('#acabado_sobrecubierta'); + this.tarifasSeleccionadas = JSON.parse(this.selectElement.attr('data-selected') || '[]'); + } + + init() { + + const self = this; + + this.selectElement.select2({ + placeholder: "Selecciona tarifas...", + allowClear: true, + ajax: { + url: "/serviciosacabado/gettarifas", + type: "GET", + dataType: "json", + delay: 250, + data: function (params) { + return { + id: window.location.pathname.split('/').pop(), + search: params.term , + acabado_cubierta: self.acabado_cubierta.prop('checked')?1:0, + acabado_sobrecubierta: self.acabado_sobrecubierta.prop('checked')?1:0 + }; + }, + processResults: function (data) { + return { + results: data.map(item => ({ + id: item.id, + text: item.nombre + })) + }; + }, + cache: true + } + }); + + // Si hay tarifas preseleccionadas, cargarlas manualmente + if (this.tarifasSeleccionadas.length > 0) { + $.ajax({ + url: "/serviciosacabado/getselectedtarifas", + type: "GET", + dataType: "json", + data: { ids: self.tarifasSeleccionadas }, + success: (data) => { + let tarifasPreseleccionadas = data.map(item => ({ + id: item.id, + text: item.nombre + })); + + self.selectElement.append( + tarifasPreseleccionadas.map(item => + new Option(item.text, item.id, true, true) + ) + ).trigger("change"); + } + }); + } + + } + +} + + + +$(function () { + new editServiciosAcabado().init(); +}) + +export default editServiciosAcabado; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/tarifas/serviciosAcabado/list.js b/httpdocs/assets/js/safekat/pages/tarifas/serviciosAcabado/list.js index f92de65e..9eabf9b0 100644 --- a/httpdocs/assets/js/safekat/pages/tarifas/serviciosAcabado/list.js +++ b/httpdocs/assets/js/safekat/pages/tarifas/serviciosAcabado/list.js @@ -1,25 +1,58 @@ -class listServiciosAcabado{ +import Ajax from '../../../components/ajax.js'; +import ConfirmDeleteModal from '../../../components/ConfirmDeleteModal.js'; - constructor(){} +class listServiciosAcabado { - init(){ + constructor() { + + this.deleteModal = null; + } + + init() { + const self = this; this.table = $('#tableOfServiciosAcabado'); this.datatableColumns = [ { data: 'id', searchable: true, sortable: true, width: "10%" }, { data: 'nombre', searchable: true, sortable: true, width: "40%" }, - { data: 'acabado_cubierta', sortable: true, width: "10%", render: this.#renderBoolCell.bind(this) }, + { data: 'acabado_cubierta', sortable: true, width: "10%", render: this.#renderBoolCell.bind(this) }, { data: 'acabado_sobrecubierta', sortable: false, width: "10%", render: this.#renderBoolCell.bind(this) }, - { data: 'mostrar_en_presupuesto_cliente', searchable: false, sortable: true, width: "1exit0%", render: this.#renderBoolCell.bind(this) }, + { data: 'mostrar_en_presupuesto_cliente', searchable: false, sortable: true, width: "1exit0%", render: this.#renderBoolCell.bind(this) }, { data: 'user_updated', searchable: true, sortable: true }, { data: 'updated_at', searchable: false, sortable: true }, { - data: 'action', searchable: false, sortable: false, width: "10%", render: this.#renderActionCell.bind(this) + data: 'action', searchable: false, sortable: false, width: "10%" }, ] this.initDatatableTareas(); + + this.deleteModal = new ConfirmDeleteModal('tarifascliente'); + this.deleteModal.init(); + + this.table.on('click', '.btn-delete', function (e) { + + self.deleteModal.setData($(this).attr('data-id')); + self.deleteModal.show(() => { + if ($.isNumeric(self.deleteModal.getData())) { + new Ajax( + '/serviciosacabado/delete/' + self.deleteModal.getData(), + {}, + {}, + (response) => { + if (response.id) { + self.datatableTareas.ajax.reload(); + popSuccessAlert(response.msg); + } + } + ).get(); + } + }); + }); + this.table.on('click', '.btn-edit', function (e) { + window.location.href = '/serviciosacabado/edit/' + $(this).attr('data-id'); + }); } initDatatableTareas() { @@ -34,7 +67,7 @@ class listServiciosAcabado{ bottomEnd: 'paging' }, serverSide: true, - responsive : true, + responsive: true, pageLength: 25, language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" @@ -44,14 +77,6 @@ class listServiciosAcabado{ }); } - #renderActionCell(d, t) { - - let cell = `
- - -
` - return cell; - } #renderBoolCell(d, t) { @@ -62,7 +87,7 @@ class listServiciosAcabado{ -$(function() { +$(function () { new listServiciosAcabado().init(); })