diff --git a/ci4/app/Config/Routes/ConfiguracionRoutes.php b/ci4/app/Config/Routes/ConfiguracionRoutes.php index 947c4e8e..1dd58f89 100644 --- a/ci4/app/Config/Routes/ConfiguracionRoutes.php +++ b/ci4/app/Config/Routes/ConfiguracionRoutes.php @@ -12,10 +12,11 @@ $routes->group('configuracion', ['namespace' => 'App\Controllers\Configuracion'] $routes->get('', 'Paises::index', ['as' => 'paisList']); $routes->get('add', 'Paises::add', ['as' => 'newPais']); $routes->post('add', 'Paises::add', ['as' => 'createPais']); + $routes->get('delete/(:num)', 'Paises::delete/$1'); $routes->post('create', 'Paises::create', ['as' => 'ajaxCreatePais']); $routes->put('update/(:num)', 'Paises::update/$1', ['as' => 'ajaxUpdatePais']); $routes->match(['get', 'post'], 'edit/(:num)', 'Paises::edit/$1', ['as' => 'updatePais']); - $routes->post('datatable', 'Paises::datatable', ['as' => 'dataTableOfPaises']); + $routes->get('datatable', 'Paises::datatable', ['as' => 'dataTableOfPaises']); $routes->post('allmenuitems', 'Paises::allItemsSelect', ['as' => 'select2ItemsOfPaises']); $routes->post('menuitems', 'Paises::menuItems', ['as' => 'menuItemsOfPaises']); $routes->get('menuitems2', 'Paises::menuItems2', ['as' => 'menuItemsOfPaises2']); diff --git a/ci4/app/Config/Routing.php b/ci4/app/Config/Routing.php index ee51edc5..3ffef3bb 100644 --- a/ci4/app/Config/Routing.php +++ b/ci4/app/Config/Routing.php @@ -88,7 +88,7 @@ class Routing extends BaseRouting * * If FALSE, will stop searching and do NO automatic routing. */ - public bool $autoRoute = true; + public bool $autoRoute = false; /** * If TRUE, will enable the use of the 'prioritize' option diff --git a/ci4/app/Controllers/Configuracion/Paises.php b/ci4/app/Controllers/Configuracion/Paises.php index a9d8b5d1..20668475 100755 --- a/ci4/app/Controllers/Configuracion/Paises.php +++ b/ci4/app/Controllers/Configuracion/Paises.php @@ -1,4 +1,5 @@ -request->getPost()) : + if ($this->request->getPost()): $postData = $this->request->getPost(); $sanitizedData = $this->sanitized($postData, true); $noException = true; - if ($successfulResult = $this->canValidate()) : + if ($successfulResult = $this->canValidate()): - if ($this->canValidate()) : + if ($this->canValidate()): try { $successfulResult = $this->model->skipValidation(true)->save($sanitizedData); } catch (\Exception $e) { @@ -86,14 +89,14 @@ class Paises extends \App\Controllers\BaseResourceController $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission endif; - if ($noException && $successfulResult) : + if ($noException && $successfulResult): $id = $this->model->db->insertID(); $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.'; - if ($thenRedirect) : - if (!empty($this->indexRoute)) : + if ($thenRedirect): + if (!empty($this->indexRoute)): return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); else: return $this->redirect2listView('sweet-success', $message); @@ -117,20 +120,20 @@ class Paises extends \App\Controllers\BaseResourceController public function edit($requestedId = null) { - if ($requestedId == null) : + if ($requestedId == null): return $this->redirect2listView(); endif; $id = filter_var($requestedId, FILTER_SANITIZE_URL); $paisEntity = $this->model->find($id); - if ($paisEntity == false) : + if ($paisEntity == false): $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Paises.pais')), $id]); return $this->redirect2listView('sweet-error', $message); endif; - - if ($this->request->getPost()) : + + if ($this->request->getPost()): $nullIfEmpty = true; // !(phpversion() >= '8.1'); @@ -143,10 +146,10 @@ class Paises extends \App\Controllers\BaseResourceController $noException = true; - if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) : - if ($this->canValidate()) : + if ($this->canValidate()): try { $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } catch (\Exception $e) { @@ -163,12 +166,12 @@ class Paises extends \App\Controllers\BaseResourceController $thenRedirect = false; endif; - if ($noException && $successfulResult) : + if ($noException && $successfulResult): $id = $paisEntity->id ?? $id; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; - if ($thenRedirect) : - if (!empty($this->indexRoute)) : + if ($thenRedirect): + if (!empty($this->indexRoute)): return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); else: return $this->redirect2listView('sweet-success', $message); @@ -193,30 +196,38 @@ class Paises extends \App\Controllers\BaseResourceController 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 = PaisModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; - $dir = $reqData['order']['0']['dir'] ?? 'asc'; + $q = $this->model->getDatatableQuery(); - $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + $result = DataTable::of($q) + ->edit( + "show_erp", + function ($row, $meta) { + if($row->show_erp == 1) { + return ''; + }else{ + return ''; + } + } + ) + ->add("actionBtns", callback: function ($q) { + $actions = ''; + if (auth()->user()->can('paises.edit')) { + $actions .= ' +
'; + } + if (auth()->user()->can('paises.delete')) { + $actions .= ' + '; + } + return $actions; + }); + + return $result->toJson(returnAsObject: true); - 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() @@ -277,7 +288,7 @@ class Paises extends \App\Controllers\BaseResourceController "id", "nombre as name" ] - )->orderBy("nombre", "asc"); + )->orderBy("nombre", "asc"); if ($this->request->getGet("q")) { $query->groupStart() ->orLike("lg_paises.nombre", $this->request->getGet("q")) diff --git a/ci4/app/Entities/Configuracion/PaisEntity.php b/ci4/app/Entities/Configuracion/PaisEntity.php index 9460f544..9fb8f33f 100755 --- a/ci4/app/Entities/Configuracion/PaisEntity.php +++ b/ci4/app/Entities/Configuracion/PaisEntity.php @@ -14,7 +14,7 @@ class PaisEntity extends \CodeIgniter\Entity\Entity "url_erp" => null, "user_erp" => null, "key_erp" => null, - "show_erp" => false, + "show_erp" => null, ]; protected $casts = [ "show_erp" => "boolean", diff --git a/ci4/app/Models/Configuracion/PaisModel.php b/ci4/app/Models/Configuracion/PaisModel.php index e94deab3..aaba9cbd 100755 --- a/ci4/app/Models/Configuracion/PaisModel.php +++ b/ci4/app/Models/Configuracion/PaisModel.php @@ -12,17 +12,6 @@ class PaisModel extends \App\Models\BaseModel */ protected $useAutoIncrement = true; - const SORTABLE = [ - 1 => "t1.id", - 2 => "t1.nombre", - 3 => "t1.code", - 4 => "t1.code3", - 5 => "t1.moneda", - 6 => "t1.url_erp", - 7 => "t1.user_erp", - 8 => "t1.key_erp", - 9 => "t1.show_erp", - ]; protected $allowedFields = ["nombre", "code", "code3", "moneda", "url_erp", "user_erp", "key_erp", "show_erp"]; protected $returnType = "App\Entities\Configuracion\PaisEntity"; @@ -91,38 +80,24 @@ class PaisModel extends \App\Models\BaseModel /** * Get resource data. * - * @param string $search - * * @return \CodeIgniter\Database\BaseBuilder */ - public function getResource(string $search = "") + public function getDatatableQuery() { $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id AS id, t1.nombre AS nombre, t1.code AS code, t1.code3 AS code3, t1.moneda AS moneda, t1.url_erp AS url_erp, t1.user_erp AS user_erp, t1.key_erp AS key_erp, t1.show_erp AS show_erp" + "t1.id AS id, + t1.nombre AS nombre, + t1.code AS code, + t1.code3 AS code3, + t1.moneda AS moneda, + t1.url_erp AS url_erp, + t1.user_erp AS user_erp, + t1.key_erp AS key_erp, + t1.show_erp AS show_erp" ); - return empty($search) - ? $builder - : $builder - ->groupStart() - ->like("t1.id", $search) - ->orLike("t1.nombre", $search) - ->orLike("t1.code", $search) - ->orLike("t1.code3", $search) - ->orLike("t1.moneda", $search) - ->orLike("t1.url_erp", $search) - ->orLike("t1.user_erp", $search) - ->orLike("t1.key_erp", $search) - ->orLike("t1.id", $search) - ->orLike("t1.nombre", $search) - ->orLike("t1.code", $search) - ->orLike("t1.code3", $search) - ->orLike("t1.moneda", $search) - ->orLike("t1.url_erp", $search) - ->orLike("t1.user_erp", $search) - ->orLike("t1.key_erp", $search) - ->groupEnd(); + return $builder; } } diff --git a/ci4/app/Views/themes/vuexy/form/configuracion/paises/viewPaisForm.php b/ci4/app/Views/themes/vuexy/form/configuracion/paises/viewPaisForm.php index 0ad05ebc..00a34130 100644 --- a/ci4/app/Views/themes/vuexy/form/configuracion/paises/viewPaisForm.php +++ b/ci4/app/Views/themes/vuexy/form/configuracion/paises/viewPaisForm.php @@ -1,5 +1,5 @@ -= $this->include("themes_commonPartialsBs/select2bs5") ?> -= $this->include("themes_commonPartialsBs/sweetalert") ?> += $this->include("themes/_commonPartialsBs/select2bs5") ?> += $this->include("themes/_commonPartialsBs/sweetalert") ?> = $this->extend('themes/vuexy/main/defaultlayout') ?> = $this->section("content") ?>