From 325ae2bd95acebfb40782288596b3e3666fffcc3 Mon Sep 17 00:00:00 2001 From: Jaime Jimenez Date: Thu, 15 Jun 2023 21:53:01 +0200 Subject: [PATCH] trabajando en el form --- ci4/app/Config/Routes.php | 38 +- .../Tarifas/Tarifamanipuladolineas.php | 392 ++++++++++++++++++ ...famanipulado.php => Tarifasmanipulado.php} | 123 ++++-- .../Tarifas/TarifaManipuladoLinea.php | 33 ++ .../Tarifas/TarifamanipuladoEntity.php | 21 +- ci4/app/Language/es/Tarifamanipulado.php | 2 +- .../Tarifas/TarifaManipuladoLineaModel.php | 127 ++++++ .../Models/Tarifas/TarifamanipuladoModel.php | 105 ++--- .../manipulado/_tarifamanipuladoFormItems.php | 69 +-- .../manipulado/viewTarifamanipuladoForm.php | 256 +++++++++++- .../manipulado/viewTarifamanipuladoList.php | 212 +++++----- .../backend/vuexy/main/menu_impresion.php | 4 +- 12 files changed, 1066 insertions(+), 316 deletions(-) create mode 100644 ci4/app/Controllers/Tarifas/Tarifamanipuladolineas.php rename ci4/app/Controllers/Tarifas/{Tarifamanipulado.php => Tarifasmanipulado.php} (64%) create mode 100644 ci4/app/Entities/Tarifas/TarifaManipuladoLinea.php create mode 100644 ci4/app/Models/Tarifas/TarifaManipuladoLineaModel.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 99af8b54..087f8c93 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -115,18 +115,34 @@ $routes->group('tarifapreimpresion', ['namespace' => 'App\Controllers\Tarifas'], }); -$routes->group('tarifamanipulado', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { - $routes->get('', 'Tarifamanipulado::index', ['as' => 'tarifamanipuladoList']); - $routes->get('index', 'Tarifamanipulado::index', ['as' => 'tarifamanipuladoIndex']); - $routes->get('list', 'Tarifamanipulado::index', ['as' => 'tarifamanipuladoList2']); - $routes->get('add', 'Tarifamanipulado::add', ['as' => 'newTarifamanipulado']); - $routes->post('add', 'Tarifamanipulado::add', ['as' => 'createTarifamanipulado']); - $routes->get('edit/(:num)', 'Tarifamanipulado::edit/$1', ['as' => 'editTarifamanipulado']); - $routes->post('edit/(:num)', 'Tarifamanipulado::edit/$1', ['as' => 'updateTarifamanipulado']); - $routes->get('delete/(:num)', 'Tarifamanipulado::delete/$1', ['as' => 'deleteTarifamanipulado']); - $routes->post('allmenuitems', 'Tarifamanipulado::allItemsSelect', ['as' => 'select2ItemsOfTarifasmanipulado']); - $routes->post('menuitems', 'Tarifamanipulado::menuItems', ['as' => 'menuItemsOfTarifasmanipulado']); +$routes->group('tarifasmanipulado', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { + $routes->get('', 'Tarifasmanipulado::index', ['as' => 'tarifaManipuladoList']); + $routes->get('add', 'Tarifasmanipulado::add', ['as' => 'newTarifaManipulado']); + $routes->post('add', 'Tarifasmanipulado::add', ['as' => 'createTarifaManipulado']); + $routes->post('create', 'Tarifasmanipulado::create', ['as' => 'ajaxCreateTarifaManipulado']); + $routes->put('(:num)/update', 'Tarifasmanipulado::update/$1', ['as' => 'ajaxUpdateTarifaManipulado']); + $routes->post('edit/(:num)', 'Tarifasmanipulado::edit/$1', ['as' => 'updateTarifaManipulado']); + $routes->get('delete/(:num)', 'Tarifasmanipulado::delete/$1', ['as' => 'deleteTarifaManipulado']); + $routes->post('datatable', 'Tarifasmanipulado::datatable', ['as' => 'dataTableOfTarifasManipulado']); + $routes->post('allmenuitems', 'Tarifasmanipulado::allItemsSelect', ['as' => 'select2ItemsOfTarifasManipulado']); + $routes->post('menuitems', 'Tarifasmanipulado::menuItems', ['as' => 'menuItemsOfTarifasManipulado']); }); +$routes->resource('tarifamanipulado', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasmanipulado', 'except' => 'show,new,create,update']); + + +$routes->group('tarifamanipuladolineas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { + $routes->get('', 'Tarifamanipuladolineas::index', ['as' => 'tarifaManipuladoLineaList']); + $routes->get('add', 'Tarifamanipuladolineas::add', ['as' => 'newTarifaManipuladoLinea']); + $routes->post('add', 'Tarifamanipuladolineas::add', ['as' => 'createTarifaManipuladoLinea']); + $routes->post('create', 'Tarifamanipuladolineas::create', ['as' => 'ajaxCreateTarifaManipuladoLinea']); + $routes->put('(:num)/update', 'Tarifamanipuladolineas::update/$1', ['as' => 'ajaxUpdateTarifaManipuladoLinea']); + $routes->post('(:num)/edit', 'Tarifamanipuladolineas::edit/$1', ['as' => 'updateTarifaManipuladoLinea']); + $routes->post('datatable', 'Tarifamanipuladolineas::datatable', ['as' => 'dataTableOfTarifaManipuladoLineas']); + $routes->post('datatable_editor', 'Tarifamanipuladolineas::datatable_editor', ['as' => 'editorOfTarifaManipuladoLineas']); + $routes->post('allmenuitems', 'Tarifamanipuladolineas::allItemsSelect', ['as' => 'select2ItemsOfTarifaManipuladoLineas']); + $routes->post('menuitems', 'Tarifamanipuladolineas::menuItems', ['as' => 'menuItemsOfTarifaManipuladoLineas']); +}); +$routes->resource('tarifamanipuladolineas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifamanipuladolineas', 'except' => 'show,new,create,update']); $routes->group('tipologiaslibros', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { diff --git a/ci4/app/Controllers/Tarifas/Tarifamanipuladolineas.php b/ci4/app/Controllers/Tarifas/Tarifamanipuladolineas.php new file mode 100644 index 00000000..ba135419 --- /dev/null +++ b/ci4/app/Controllers/Tarifas/Tarifamanipuladolineas.php @@ -0,0 +1,392 @@ +viewData['pageTitle'] = lang('TarifaManipuladoLineas.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + parent::initController($request, $response, $logger); + } + + + public function index() { + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifaManipuladoLineas.tarifamanipuladoLinea')]), + 'tarifaManipuladoLinea' => new TarifaManipuladoLinea(), + 'usingServerSideDataTable' => true, + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath.'viewTarifaManipuladoLineaList', $viewData); + } + + + public function add() { + + + + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + + 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', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]); + $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', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]).'.'; + $message .= anchor( "tarifamanipuladolineas/{$id}/edit" , lang('Basic.global.continueEditing').'?'); + $message = ucfirst(str_replace("'", "\'", $message)); + + 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['tarifaManipuladoLinea'] = isset($sanitizedData) ? new TarifaManipuladoLinea($sanitizedData) : new TarifaManipuladoLinea(); + + $this->viewData['formAction'] = route_to('createTarifaManipuladoLinea'); + + $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifaManipuladoLineas.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); + $tarifaManipuladoLinea = $this->model->find($id); + + if ($tarifaManipuladoLinea == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea')), $id]); + return $this->redirect2listView('sweet-error', $message); + endif; + + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + + + $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('TarifaManipuladoLineas.tarifamanipuladoLinea'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $tarifaManipuladoLinea->fill($sanitizedData); + + $thenRedirect = true; + endif; + if ($noException && $successfulResult) : + $id = $tarifaManipuladoLinea->id ?? $id; + $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]).'.'; + $message .= anchor( "tarifamanipuladolineas/{$id}/edit" , lang('Basic.global.continueEditing').'?'); + $message = ucfirst(str_replace("'", "\'", $message)); + + 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['tarifaManipuladoLinea'] = $tarifaManipuladoLinea; + + $this->viewData['formAction'] = route_to('updateTarifaManipuladoLinea', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifaManipuladoLineas.moduleTitle').' '.lang('Basic.global.edit3'); + + + return $this->displayForm(__METHOD__, $id); + } // end function edit(...) + + + public function datatable_editor() { + if ($this->request->isAJAX()) { + + include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); + + // Build our Editor instance and process the data coming from _POST + $response = Editor::inst( $db, 'tarifa_manipulado_lineas' ) + ->fields( + Field::inst( 'tirada_min' ) + ->validator( 'Validate::numeric', array( + 'message' => lang('TarifaAcabadoLineas.validation.tirada_min.decimal') ) + ) + ->validator( 'Validate::notEmpty',array( + 'message' => lang('TarifaAcabadoLineas.validation.tirada_min.required') ) + ), + Field::inst( 'tirada_max' ) + ->validator( 'Validate::numeric', array( + 'message' => lang('TarifaAcabadoLineas.validation.tirada_max.decimal') ) + ) + ->validator( 'Validate::notEmpty',array( + 'message' => lang('TarifaAcabadoLineas.validation.tirada_max.required') ) + ), + Field::inst( 'precio_min' ) + ->validator( 'Validate::numeric', array( + 'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal') ) + ) + ->validator( 'Validate::notEmpty',array( + 'message' => lang('TarifaAcabadoLineas.validation.precio_min.required') ) + ), + Field::inst( 'precio_max' ) + ->validator( 'Validate::numeric', array( + 'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal') ) + ) + ->validator( 'Validate::notEmpty',array( + 'message' => lang('TarifaAcabadoLineas.validation.precio_max.required') ) + ), + Field::inst( 'precio_unidad' ) + ->validator( 'Validate::numeric', array( + 'message' => lang('TarifaAcabadoLineas.validation.precio_unidad.decimal') ) + ) + ->validator( 'Validate::notEmpty',array( + 'message' => lang('TarifaAcabadoLineas.validation.precio_unidad.required') ) + ), + Field::inst( 'tarifa_manipulado_id' ), + Field::inst( 'user_created_id' ), + Field::inst( 'created_at' ), + Field::inst( 'user_updated_id' ), + Field::inst( 'updated_at' ), + Field::inst( 'is_deleted' ), + Field::inst( 'deleted_at' ), + + ) + ->validator( function($editor, $action, $data){ + if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){ + foreach ($data['data'] as $pkey => $values ){ + $count = $this->model->select('*') + ->where(array('tarifa_manipulado_id'=> $values['tarifa_manipulado_id'], 'tirada_min'=> $values['tirada_min'], 'tirada_max'=> $values['tirada_max'], 'is_deleted'=> 0)) + ->countAllResults(); + if ($count >= 1){ + return lang('TarifaAcabadoLineas.validation.duplicated_tirada'); + } + } + } + }) + ->on( 'preCreate', function ( $editor, &$values ) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field( 'user_created_id' ) + ->setValue( $session->id_user ); + $editor + ->field( 'created_at' ) + ->setValue( $datetime->format('Y-m-d H:i:s') ); + } ) + ->on( 'preEdit', function ( $editor, &$values ) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field( 'user_updated_id' ) + ->setValue( $session->id_user ); + $editor + ->field( 'updated_at' ) + ->setValue( $datetime->format('Y-m-d H:i:s') ); + } ) + ->debug(true) + ->process( $_POST ) + ->data(); + + + // if unique key is set in DB + if(isset($response['error'])){ + if(str_contains($response['error'], "tirada_min_tirada_max") && + str_contains($response['error'], "Duplicate entry ")){ + $response['error'] = lang('TarifaAcabadoLineas.validation.duplicated_tirada'); + } + } + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $response[$csrfTokenName] = $newTokenHash; + + echo json_encode($response); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + 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'] ?? 0; + $order = TarifaManipuladoLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $id_TM = $reqData['id_tarifamanipulado'] ?? -1; + + $resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $this->model->getResource()->countAllResults(), + $this->model->getResource($search)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function allItemsSelect() { + if ($this->request->isAJAX()) { + $onlyActiveOnes = true; + $reqVal = $this->request->getPost('val') ?? 'id'; + $menu = $this->model->getAllForMenu($reqVal.', tarifa_manipulado_id', 'tarifa_manipulado_id', $onlyActiveOnes, false); + $nonItem = new \stdClass; + $nonItem->id = ''; + $nonItem->tarifa_manipulado_id = '- '.lang('Basic.global.None').' -'; + array_unshift($menu , $nonItem); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'menu' => $menu, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function menuItems() { + if ($this->request->isAJAX()) { + $searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; + $reqId = goSanitize($this->request->getPost('id'))[0]; + $reqText = goSanitize($this->request->getPost('text'))[0]; + $onlyActiveOnes = false; + $columns2select = [$reqId ?? 'id', $reqText ?? 'tarifa_manipulado_id']; + $onlyActiveOnes = false; + $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); + $nonItem = new \stdClass; + $nonItem->id = ''; + $nonItem->text = '- '.lang('Basic.global.None').' -'; + array_unshift($menu , $nonItem); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'menu' => $menu, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + +} diff --git a/ci4/app/Controllers/Tarifas/Tarifamanipulado.php b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php similarity index 64% rename from ci4/app/Controllers/Tarifas/Tarifamanipulado.php rename to ci4/app/Controllers/Tarifas/Tarifasmanipulado.php index 46b01ae9..5418394a 100644 --- a/ci4/app/Controllers/Tarifas/Tarifamanipulado.php +++ b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php @@ -1,44 +1,62 @@ viewData['pageTitle'] = lang('Tarifamanipulado.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]; // JJO parent::initController($request, $response, $logger); - } + public function index() { - $this->viewData['usingClientSideDataTable'] = true; - - $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifamanipulado.tarifamanipulado')]); - parent::index(); + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Tarifamanipulado.tarifamanipulado')]), + 'tarifaManipuladoEntity' => new TarifaManipuladoEntity(), + 'usingServerSideDataTable' => true, + + ]; + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath.'viewTarifaManipuladoList', $viewData); } + public function add() { // JJO @@ -51,6 +69,7 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController { $nullIfEmpty = true; // !(phpversion() >= '8.1'); $postData = $this->request->getPost(); + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO @@ -60,7 +79,7 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController { $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : - + if ($this->canValidate()) : try { @@ -81,47 +100,47 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController { $id = $this->model->db->insertID(); $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]).'.'; - $message .= anchor(route_to('editTarifamanipulado', $id), lang('Basic.global.continueEditing').'?'); + $message .= anchor( "tarifamanipulado/{$id}/edit" , lang('Basic.global.continueEditing').'?'); $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : if (!empty($this->indexRoute)) : - return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message); + return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); else: - return $this->redirect2listView('successMessage', $message); + return $this->redirect2listView('sweet-success', $message); endif; else: - $this->viewData['successMessage'] = $message; + $this->session->setFlashData('sweet-success', $message); endif; endif; // $noException && $successfulResult endif; // ($requestMethod === 'post') - $this->viewData['tarifamanipuladoEntity'] = isset($sanitizedData) ? new TarifamanipuladoEntity($sanitizedData) : new TarifamanipuladoEntity(); + $this->viewData['tarifaManipuladoEntity'] = isset($sanitizedData) ? new TarifaManipuladoEntity($sanitizedData) : new TarifaManipuladoEntity(); - $this->viewData['formAction'] = route_to('createTarifamanipulado'); + $this->viewData['formAction'] = route_to('createTarifaManipulado'); - $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Tarifamanipulado.tarifamanipulado').' '.lang('Basic.global.addNewSuffix'); + $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Tarifamanipulado.moduleTitle').' '.lang('Basic.global.addNewSuffix'); return $this->displayForm(__METHOD__); } // end function add() public function edit($requestedId = null) { - + // JJO $session = session(); - + if ($requestedId == null) : return $this->redirect2listView(); endif; $id = filter_var($requestedId, FILTER_SANITIZE_URL); - $tarifamanipuladoEntity = $this->model->find($id); + $tarifaManipuladoEntity = $this->model->find($id); - if ($tarifamanipuladoEntity == false) : + if ($tarifaManipuladoEntity == false) : $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado')), $id]); - return $this->redirect2listView('errorMessage', $message); + return $this->redirect2listView('sweet-error', $message); endif; $requestMethod = $this->request->getMethod(); @@ -131,6 +150,7 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController { $nullIfEmpty = true; // !(phpversion() >= '8.1'); $postData = $this->request->getPost(); + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO @@ -156,40 +176,67 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController { endif; - $tarifamanipuladoEntity->fill($sanitizedData); + $tarifaManipuladoEntity->fill($sanitizedData); $thenRedirect = true; endif; if ($noException && $successfulResult) : - $id = $tarifamanipuladoEntity->id ?? $id; + $id = $tarifaManipuladoEntity->id ?? $id; $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]).'.'; - $message .= anchor(route_to('editTarifamanipulado', $id), lang('Basic.global.continueEditing').'?'); + $message .= anchor( "tarifamanipulado/{$id}/edit" , lang('Basic.global.continueEditing').'?'); $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : if (!empty($this->indexRoute)) : - return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message); + return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); else: - return $this->redirect2listView('successMessage', $message); + return $this->redirect2listView('sweet-success', $message); endif; else: - $this->viewData['successMessage'] = $message; + $this->session->setFlashData('sweet-success', $message); endif; endif; // $noException && $successfulResult endif; // ($requestMethod === 'post') - $this->viewData['tarifamanipuladoEntity'] = $tarifamanipuladoEntity; + $this->viewData['tarifaManipuladoEntity'] = $tarifaManipuladoEntity; - $this->viewData['formAction'] = route_to('updateTarifamanipulado', $id); + $this->viewData['formAction'] = route_to('updateTarifaManipulado', $id); - $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Tarifamanipulado.tarifamanipulado').' '.lang('Basic.global.edit3'); + $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Tarifamanipulado.moduleTitle').' '.lang('Basic.global.edit3'); return $this->displayForm(__METHOD__, $id); } // end function edit(...) - + + + 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 = TarifaManipuladoModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $this->model->getResource()->countAllResults(), + $this->model->getResource($search)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } public function allItemsSelect() { if ($this->request->isAJAX()) { @@ -212,7 +259,7 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController { return $this->failUnauthorized('Invalid request', 403); } } - + public function menuItems() { if ($this->request->isAJAX()) { $searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; @@ -238,5 +285,5 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController { return $this->failUnauthorized('Invalid request', 403); } } - + } diff --git a/ci4/app/Entities/Tarifas/TarifaManipuladoLinea.php b/ci4/app/Entities/Tarifas/TarifaManipuladoLinea.php new file mode 100644 index 00000000..eed0f449 --- /dev/null +++ b/ci4/app/Entities/Tarifas/TarifaManipuladoLinea.php @@ -0,0 +1,33 @@ + null, + "tarifa_manipulado_id" => 0, + "tirada_min" => 0, + "tirada_max" => 0, + "precio_min" => 0, + "precio_max" => 0, + "precio_unidad" => 0, + "user_created_id" => 0, + "user_updated_id" => 0, + "is_deleted" => 0, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "tarifa_manipulado_id" => "int", + "tirada_min" => "float", + "tirada_max" => "float", + "precio_min" => "float", + "precio_max" => "float", + "precio_unidad" => "float", + "user_created_id" => "int", + "user_updated_id" => "int", + "is_deleted" => "int", + ]; +} diff --git a/ci4/app/Entities/Tarifas/TarifamanipuladoEntity.php b/ci4/app/Entities/Tarifas/TarifamanipuladoEntity.php index 22c1969e..3f2476cd 100644 --- a/ci4/app/Entities/Tarifas/TarifamanipuladoEntity.php +++ b/ci4/app/Entities/Tarifas/TarifamanipuladoEntity.php @@ -3,33 +3,20 @@ namespace App\Entities\Tarifas; use CodeIgniter\Entity; -class TarifamanipuladoEntity extends \CodeIgniter\Entity\Entity +class TarifaManipuladoEntity extends \CodeIgniter\Entity\Entity { protected $attributes = [ "id" => null, "nombre" => null, - "tirada_min" => 0, - "precio_min" => 0, - "tirada_max" => 0, - "precio_max" => null, - "ajuste" => 0, - "ajuste_total_pedido" => 0, - "formula_price" => null, - "user_created_id" => 1, - "user_update_id" => 1, - "deleted_at" => null, + "user_created_id" => 0, + "user_update_id" => 0, "is_deleted" => 0, "created_at" => null, "updated_at" => null, ]; protected $casts = [ - "tirada_min" => "int", - "precio_min" => "float", - "tirada_max" => "int", - "precio_max" => "float", - "ajuste" => "float", - "ajuste_total_pedido" => "float", "user_created_id" => "int", "user_update_id" => "int", + "is_deleted" => "int", ]; } diff --git a/ci4/app/Language/es/Tarifamanipulado.php b/ci4/app/Language/es/Tarifamanipulado.php index 7cf0dd37..9b9bc6ec 100644 --- a/ci4/app/Language/es/Tarifamanipulado.php +++ b/ci4/app/Language/es/Tarifamanipulado.php @@ -13,7 +13,7 @@ return [ 'nombre' => 'Nombre', 'precioMax' => 'Precio Max', 'precioMin' => 'Precio Min', - 'tarifamanipulado' => 'Tarifas manipulado', + 'tarifamanipulado' => 'Tarifa manipulado', 'tarifamanipuladoList' => 'Lista Tarifas manipulado', 'tarifasmanipulado' => 'Tarifas manipulado', 'tiradaMax' => 'Tirada Max', diff --git a/ci4/app/Models/Tarifas/TarifaManipuladoLineaModel.php b/ci4/app/Models/Tarifas/TarifaManipuladoLineaModel.php new file mode 100644 index 00000000..8bd6000d --- /dev/null +++ b/ci4/app/Models/Tarifas/TarifaManipuladoLineaModel.php @@ -0,0 +1,127 @@ + "t1.tirada_min", + 1 => "t1.tirada_max", + 2 => "t1.precio_min", + 3 => "t1.precio_max", + 4 => "t1.precio_unidad", + ]; + + protected $allowedFields = [ + "tarifa_manipulado_id", + "tirada_min", + "tirada_max", + "precio_min", + "precio_max", + "precio_unidad", + ]; + protected $returnType = "App\Entities\Tarifas\TarifaManipuladoLinea"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + + protected $updatedField = "updated_at"; + + public static $labelField = "tarifa_manipulado_id"; + + protected $validationRules = [ + "precio_max" => [ + "label" => "TarifaManipuladoLineas.precioMax", + "rules" => "required|decimal", + ], + "precio_min" => [ + "label" => "TarifaManipuladoLineas.precioMin", + "rules" => "required|decimal", + ], + "precio_unidad" => [ + "label" => "TarifaManipuladoLineas.precioUnidad", + "rules" => "required|decimal", + ], + "tirada_max" => [ + "label" => "TarifaManipuladoLineas.tiradaMax", + "rules" => "required|decimal", + ], + "tirada_min" => [ + "label" => "TarifaManipuladoLineas.tiradaMin", + "rules" => "required|decimal", + ], + ]; + + protected $validationMessages = [ + "precio_max" => [ + "decimal" => "TarifaManipuladoLineas.validation.precio_max.decimal", + "required" => "TarifaManipuladoLineas.validation.precio_max.required", + ], + "precio_min" => [ + "decimal" => "TarifaManipuladoLineas.validation.precio_min.decimal", + "required" => "TarifaManipuladoLineas.validation.precio_min.required", + ], + "precio_unidad" => [ + "decimal" => "TarifaManipuladoLineas.validation.precio_unidad.decimal", + "required" => "TarifaManipuladoLineas.validation.precio_unidad.required", + ], + "tirada_max" => [ + "decimal" => "TarifaManipuladoLineas.validation.tirada_max.decimal", + "required" => "TarifaManipuladoLineas.validation.tirada_max.required", + ], + "tirada_min" => [ + "decimal" => "TarifaManipuladoLineas.validation.tirada_min.decimal", + "required" => "TarifaManipuladoLineas.validation.tirada_min.required", + ], + ]; + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource(string $search = "", $tarifa_manipulado_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.tarifa_manipulado_id AS tarifa_manipulado_id, t1.tirada_min AS tirada_min, t1.tirada_max AS tirada_max, t1.precio_min AS precio_min, t1.precio_max AS precio_max, t1.precio_unidad AS precio_unidad" + ); + if($tarifa_manipulado_id>=0) + { + $builder->where('tarifa_manipulado_id', $tarifa_manipulado_id); + } + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t1.tarifa_manipulado_id", $search) + ->orLike("t1.tirada_min", $search) + ->orLike("t1.tirada_max", $search) + ->orLike("t1.precio_min", $search) + ->orLike("t1.precio_max", $search) + ->orLike("t1.precio_unidad", $search) + ->orLike("t1.id", $search) + ->orLike("t1.tarifa_manipulado_id", $search) + ->orLike("t1.tirada_min", $search) + ->orLike("t1.tirada_max", $search) + ->orLike("t1.precio_min", $search) + ->orLike("t1.precio_max", $search) + ->orLike("t1.precio_unidad", $search) + ->groupEnd(); + } +} diff --git a/ci4/app/Models/Tarifas/TarifamanipuladoModel.php b/ci4/app/Models/Tarifas/TarifamanipuladoModel.php index 640325ec..ab0ee8db 100644 --- a/ci4/app/Models/Tarifas/TarifamanipuladoModel.php +++ b/ci4/app/Models/Tarifas/TarifamanipuladoModel.php @@ -1,7 +1,7 @@ "t1.nombre", + ]; + protected $allowedFields = [ "nombre", - "tirada_min", - "precio_min", - "tirada_max", - "precio_max", - "ajuste", - "ajuste_total_pedido", - "formula_price", "deleted_at", "is_deleted", "user_created_id", - "user_update_id", + "user_update_id" ]; - protected $returnType = "App\Entities\Tarifas\TarifamanipuladoEntity"; + protected $returnType = "App\Entities\Tarifas\TarifaManipuladoEntity"; protected $useTimestamps = true; protected $useSoftDeletes = false; + protected $createdField = "created_at"; + protected $updatedField = "updated_at"; - protected $deletedField = 'deleted_at'; public static $labelField = "nombre"; protected $validationRules = [ - "ajuste" => [ - "label" => "Manipuladoes.ajuste", - "rules" => "required|decimal", - ], - "ajuste_total_pedido" => [ - "label" => "Manipuladoes.ajusteTotalPedido", - "rules" => "required|decimal", - ], - "formula_price" => [ - "label" => "Manipuladoes.formulaPrice", - "rules" => "trim|required|max_length[1073241]", - ], "nombre" => [ - "label" => "Manipuladoes.nombre", + "label" => "Tarifamanipulado.nombre", "rules" => "trim|required|max_length[255]", ], - "precio_max" => [ - "label" => "Manipuladoes.precioMax", - "rules" => "required|decimal", - ], - "precio_min" => [ - "label" => "Manipuladoes.precioMin", - "rules" => "required|decimal", - ], - "tirada_max" => [ - "label" => "Manipuladoes.tiradaMax", - "rules" => "required|integer", - ], - "tirada_min" => [ - "label" => "Manipuladoes.tiradaMin", - "rules" => "required|integer", - ], ]; protected $validationMessages = [ - "ajuste" => [ - "decimal" => "Manipuladoes.validation.ajuste.decimal", - "required" => "Manipuladoes.validation.ajuste.required", - ], - "ajuste_total_pedido" => [ - "decimal" => "Manipuladoes.validation.ajuste_total_pedido.decimal", - "required" => "Manipuladoes.validation.ajuste_total_pedido.required", - ], - "formula_price" => [ - "max_length" => "Manipuladoes.validation.formula_price.max_length", - "required" => "Manipuladoes.validation.formula_price.required", - ], "nombre" => [ - "max_length" => "Manipuladoes.validation.nombre.max_length", - "required" => "Manipuladoes.validation.nombre.required", + "max_length" => "Tarifamanipulado.validation.nombre.max_length", + "required" => "Tarifamanipulado.validation.nombre.required", ], - "precio_max" => [ - "decimal" => "Manipuladoes.validation.precio_max.decimal", - "required" => "Manipuladoes.validation.precio_max.required", - ], - "precio_min" => [ - "decimal" => "Manipuladoes.validation.precio_min.decimal", - "required" => "Manipuladoes.validation.precio_min.required", - ], - "tirada_max" => [ - "integer" => "Manipuladoes.validation.tirada_max.integer", - "required" => "Manipuladoes.validation.tirada_max.required", - ], - "tirada_min" => [ - "integer" => "Manipuladoes.validation.tirada_min.integer", - "required" => "Manipuladoes.validation.tirada_min.required", - ] ]; + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource(string $search = "") + { + $builder = $this->db->table($this->table . " t1")->select("t1.id AS id, t1.nombre AS nombre"); + + //JJO + $builder->where("t1.is_deleted", 0); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.nombre", $search) + ->orLike("t1.nombre", $search) + ->groupEnd(); + } } diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/_tarifamanipuladoFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/_tarifamanipuladoFormItems.php index 43699a82..94034e98 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/_tarifamanipuladoFormItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/_tarifamanipuladoFormItems.php @@ -1,77 +1,12 @@
-
+
- +
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
-
-
- - -
- - - -
- -
- - -
- */ ?>
\ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoForm.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoForm.php index d3d49d1c..f2ae71ec 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoForm.php @@ -1,5 +1,7 @@ +include("themes/_commonPartialsBs/datatables") ?> include("themes/_commonPartialsBs/select2bs5") ?> -extend('themes/backend/vuexy/main/defaultlayout') ?> +include("themes/_commonPartialsBs/sweetalert") ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> section("content") ?>
@@ -7,21 +9,265 @@

-
+
getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> - +
+ +
+
+

+ + +

+ +
+
+ + + + + + + + + + + + + + + +
+
+
+
+
+ + endSection() ?> + + +section("additionalInlineJs") ?> + + const lastColNr = $('#tableOfTarifamanipuladolineas').find("tr:first th").length - 1; + const url = window.location.href; + const url_parts = url.split('/'); + if(url_parts[url_parts.length-2] == 'edit'){ + id = url_parts[url_parts.length-1]; + } + else{ + id = -1; + } + + const actionBtns = function(data) { + return ` + + + + `; + }; + + + editor = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfTarifamanipuladolineas", + idSrc: 'id', + fields: [ { + name: "tirada_min" + }, { + name: "tirada_max" + }, { + name: "precio_min" + }, { + name: "precio_max" + }, { + name: "precio_unidad" + },{ + "name": "tarifa_manipulado_id", + "type": "hidden" + },{ + "name": "deleted_at", + "type": "hidden" + },{ + "name": "is_deleted", + "type": "hidden" + }, + ] + } ); + + editor.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['tarifa_manipulado_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['tarifa_manipulado_id'] = id; + } + } + }); + + + editor.on( 'postSubmit', function ( e, json, data, action ) { + + yeniden(json.); + }); + + editor.on( 'submitSuccess', function ( e, json, data, action ) { + + theTable.clearPipeline(); + theTable.draw(); + }); + + + var theTable = $('#tableOfTarifamanipuladolineas').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: "Bltp", + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + id_tarifamanipulado: id, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + { 'data': 'tirada_min' }, + { 'data': 'tirada_max' }, + { 'data': 'precio_min' }, + { 'data': 'precio_max' }, + { 'data': 'precio_unidad' }, + { + data: actionBtns, + className: 'row-edit dt-center' + } + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + }, + {"orderData": [ 0, 1 ], "targets": 0 }, + + ], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ] + } ); + + + + // Activate an inline edit on click of a table cell + $('#tableOfTarifamanipuladolineas').on( 'click', 'tbody span.edit', function (e) { + editor.inline( + theTable.cells(this.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + + // Delete row + $('#tableOfTarifamanipuladolineas').on( 'click', 'tbody span.remove', function (e) { + + 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(); + + } + }); + }); + + + + + + + +endSection() ?> + +section('css') ?> + + + +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + + + + + + +endSection() ?> + diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoList.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoList.php index e783cb53..d14ad577 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoList.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/manipulado/viewTarifamanipuladoList.php @@ -1,4 +1,5 @@ include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/sweetalert') ?> extend('themes/backend/vuexy/main/defaultlayout') ?> section('content'); ?>
@@ -7,87 +8,20 @@

- 'btn btn-primary float-end']); ?> + 'btn btn-primary float-end']); ?>
- +
- - */ ?> - - - - - - - - - - - - */ ?> - - - - id ?> - - */ ?> - - - - - - - - - - user_created_id) ?> - - - - - */ ?> - - -
- nombre) || strlen($item->nombre) < 51 ? esc($item->nombre) : character_limiter(esc($item->nombre), 50) ?> - - tirada_min) ?> - - tirada_max) ?> - - precio_min) ?> - - precio_max) ?> - - ajuste) ?> - - ajuste_total_pedido) ?> - - formula_price) || strlen($item->formula_price) < 51 ? esc($item->formula_price) : character_limiter(esc($item->formula_price), 50) ?> - - user_update_id) ?> - - created_at) ? '' : date('d/m/Y H:m:s', strtotime($item->created_at)) ?> - - updated_at) ? '' : date('d/m/Y H:m:s', strtotime($item->updated_at)) ?> - - id), lang('Basic.global.edit'), ['class'=>'btn btn-sm btn-warning btn-edit me-1', 'data-id'=>$item->id,]); ?> - 'btn btn-sm btn-danger btn-delete ms-1', 'data-href'=>route_to('deleteTarifamanipulado', $item->id), 'data-bs-toggle'=>'modal', 'data-bs-target'=>'#confirm2delete']); ?> -
@@ -98,6 +32,110 @@
+endSection() ?> + + +section('additionalInlineJs') ?> + + const lastColNr = $('#tableOfTarifasmanipulado').find("tr:first th").length - 1; + const actionBtns = function(data) { + return ` +
+ + +
+ `; + }; + theTable = $('#tableOfTarifasmanipulado').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], + pageLength: 10, + lengthChange: true, + "dom": 'lfBrtip', + "buttons": [ + 'copy', 'csv', 'excel', 'print', { + extend: 'pdfHtml5', + orientation: 'landscape', + pageSize: 'A4' + } + ], + stateSave: true, + order: [[0, 'asc']], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + } + ], + columns : [ + { 'data': 'nombre' }, + { 'data': actionBtns } + ] + }); + + + + +$(document).on('click', '.btn-edit', function(e) { + //window.location.href = `/${$(this).attr('data-id')}/edit`; + window.location.href = `/tarifas/tarifasmanipulado/edit/${$(this).attr('data-id')}`; + }); + +$(document).on('click', '.btn-delete', function(e) { + 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) { + $.ajax({ + //url: `/${dataId}`, + //method: 'DELETE', + url: `/tarifas/tarifasmanipulado/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + Toast.fire({ + icon: 'success', + title: data.msg ?? jqXHR.statusText, + }); + + theTable.clearPipeline(); + theTable.row($(row)).invalidate().draw(); + }).fail((jqXHR, textStatus, errorThrown) => { + Toast.fire({ + icon: 'error', + title: jqXHR.responseJSON.messages.error, + }); + }) + } + }); + }); + + + + endSection() ?> @@ -119,39 +157,3 @@ endSection() ?> -section('additionalInlineJs') ?> - - const lastColNr2 = $(".using-exportable-data-table").find("tr:first th").length - 1; - theTable = $('.using-exportable-data-table').DataTable({ - "responsive": true, - "paging": true, - "lengthMenu": [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], - "pageLength": 10, - "lengthChange": true, - "searching": true, - "ordering": true, - "info": true, - "dom": 'lfBrtip', // 'lfBrtip', // you can try different layout combinations by uncommenting one or the other - // "dom": '<"top"lf><"clear">rt<"bottom"ipB><"clear">', // remember to comment this line if you uncomment the above - "buttons": [ - 'copy', 'csv', 'excel', 'print', { - extend: 'pdfHtml5', - orientation: 'landscape', - pageSize: 'A4' - } - ], - "autoWidth": true, - "scrollX": true, - "stateSave": true, - "language": { - url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" - }, - "columnDefs": [ - { - orderable: false, - searchable: false, - targets: [0,lastColNr2] - } - ] - }); -endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php b/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php index 60bed43b..01355b6f 100644 --- a/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php +++ b/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php @@ -361,10 +361,10 @@ - 0): ?> + 0): ?> 0): ?>