diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 3ae7f096..ea5a5949 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -34,7 +34,18 @@ $routes->setAutoRoute(true); $routes->group('', [], function($routes) { - + $routes->group('paises', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { + $routes->get('', 'Paises::index', ['as' => 'paisList']); + $routes->get('index', 'Paises::index', ['as' => 'paisIndex']); + $routes->get('list', 'Paises::index', ['as' => 'paisList2']); + $routes->get('add', 'Paises::add', ['as' => 'newPais']); + $routes->post('add', 'Paises::add', ['as' => 'createPais']); + $routes->get('edit/(:num)', 'Paises::edit/$1', ['as' => 'editPais']); + $routes->post('edit/(:num)', 'Paises::edit/$1', ['as' => 'updatePais']); + $routes->get('delete/(:num)', 'Paises::delete/$1', ['as' => 'deletePais']); + $routes->post('allmenuitems', 'Paises::allItemsSelect', ['as' => 'select2ItemsOfPaises']); + $routes->post('menuitems', 'Paises::menuItems', ['as' => 'menuItemsOfPaises']); + }); $routes->group('tarifaacabado', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { $routes->get('', 'Tarifaacabado::index', ['as' => 'tarifaacabadoList']); diff --git a/ci4/app/Controllers/Configuracion/Paises.php b/ci4/app/Controllers/Configuracion/Paises.php new file mode 100644 index 00000000..ff527a2c --- /dev/null +++ b/ci4/app/Controllers/Configuracion/Paises.php @@ -0,0 +1,231 @@ +viewData['pageTitle'] = lang('Paises.moduleTitle'); + self::$viewPath = getenv('theme.path').'form/configuracion/paises/'; + + parent::initController($request, $response, $logger); + + } + + public function index() { + + $this->viewData['usingClientSideDataTable'] = true; + + $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]); + parent::index(); + + } + + 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('Paises.pais'))]); + $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('Paises.pais'))]).'.'; + $message .= anchor(route_to('editPais', $id), 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); + else: + return $this->redirect2listView('successMessage', $message); + endif; + else: + $this->viewData['successMessage'] = $message; + endif; + + endif; // $noException && $successfulResult + + endif; // ($requestMethod === 'post') + + $this->viewData['pais'] = isset($sanitizedData) ? new Pais($sanitizedData) : new Pais(); + + $this->viewData['formAction'] = route_to('createPais'); + + $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Paises.pais').' '.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); + $pais = $this->model->find($id); + + if ($pais == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Paises.pais')), $id]); + return $this->redirect2listView('errorMessage', $message); + endif; + + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + if ($this->request->getPost('show_erp') == null ) { + $sanitizedData['show_erp'] = 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('Paises.pais'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $pais->fill($sanitizedData); + + $thenRedirect = true; + endif; + if ($noException && $successfulResult) : + $id = $pais->id ?? $id; + $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Paises.pais'))]).'.'; + $message .= anchor(route_to('editPais', $id), 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); + else: + return $this->redirect2listView('successMessage', $message); + endif; + else: + $this->viewData['successMessage'] = $message; + endif; + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $this->viewData['pais'] = $pais; + + $this->viewData['formAction'] = route_to('updatePais', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Paises.pais').' '.lang('Basic.global.edit3'); + + + return $this->displayForm(__METHOD__, $id); + } // end function edit(...) + + + + public function allItemsSelect() { + if ($this->request->isAJAX()) { + $onlyActiveOnes = true; + $reqVal = $this->request->getPost('val') ?? 'id'; + $menu = $this->model->getAllForMenu($reqVal.', Select a field...', 'Select a field...', $onlyActiveOnes, false); + $nonItem = new \stdClass; + $nonItem->id = ''; + //$nonItem->'Select a field...' = '- '.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 ?? 'Select a field...']; + $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/Entities/Configuracion/Pais.php b/ci4/app/Entities/Configuracion/Pais.php new file mode 100644 index 00000000..ca30333e --- /dev/null +++ b/ci4/app/Entities/Configuracion/Pais.php @@ -0,0 +1,22 @@ + null, + "nombre" => null, + "code" => null, + "code3" => null, + "moneda" => null, + "url_erp" => null, + "user_erp" => null, + "key_erp" => null, + "show_erp" => false, + ]; + protected $casts = [ + "show_erp" => "boolean", + ]; +} diff --git a/ci4/app/Filters/LoginAuthFilter.php b/ci4/app/Filters/LoginAuthFilter.php index f74bff93..d6a6da4c 100644 --- a/ci4/app/Filters/LoginAuthFilter.php +++ b/ci4/app/Filters/LoginAuthFilter.php @@ -139,7 +139,7 @@ class LoginAuthFilter implements FilterInterface 'Integration', 'Migrate', 'Test', - + 'GoBaseController' ]; } diff --git a/ci4/app/Helpers/general_helper.php b/ci4/app/Helpers/general_helper.php index 5d00edb2..4a65b9b8 100644 --- a/ci4/app/Helpers/general_helper.php +++ b/ci4/app/Helpers/general_helper.php @@ -190,6 +190,7 @@ function getDictionary($word=''){ 'Serviciocliente' => lang("App.permisos_serviciocliente"), 'Calendario' => lang("App.permisos_calendario"), 'Correo' => lang("App.permisos_correo"), + 'Paises' => lang("App.permisos_paises"), 'Presupuestos' => lang("App.permisos_presupuestos"), 'Presupuesto' => lang("App.permisos_presupuestos"), diff --git a/ci4/app/Language/en/App.php b/ci4/app/Language/en/App.php index 120021fb..aa4f8ac4 100644 --- a/ci4/app/Language/en/App.php +++ b/ci4/app/Language/en/App.php @@ -638,6 +638,7 @@ return [ "permisos_serviciocliente" => "Customer service", "permisos_calendario" => "Calendar", "permisos_correo" => "Mail", + "permisos_paises" => "Countries", "permisos_presupuestos" => "Budgets", "permisos_presupuestomaquetacion" => "Layout", @@ -674,6 +675,7 @@ return [ "menu_configuration" => "Settings", "menu_calendario" => "Calendar", + "menu_paises" => "Countries", "menu_correo" => "Mail", "menu_formaspago" => "Payment methods", "menu_imposiciones" => "Impositions", diff --git a/ci4/app/Language/en/Paises.php b/ci4/app/Language/en/Paises.php index 4f672819..ad8ff430 100644 --- a/ci4/app/Language/en/Paises.php +++ b/ci4/app/Language/en/Paises.php @@ -8,11 +8,11 @@ return [ 'id' => 'ID', 'keyErp' => 'Key Erp', 'moduleTitle' => 'Paises', - 'moneda' => 'Moneda', - 'nombre' => 'Nombre', - 'pais' => 'Pais', - 'paisList' => 'Pais List', - 'paises' => 'Paises', + 'moneda' => 'Currency', + 'nombre' => 'Name', + 'pais' => 'Country', + 'paisList' => 'Country List', + 'paises' => 'Countries', 'showErp' => 'Show Erp', 'urlErp' => 'URL Erp', 'userErp' => 'User Erp', diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 4646ffc3..23d69f82 100644 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -638,6 +638,7 @@ return [ "permisos_serviciocliente" => "Servicio cliente", "permisos_calendario" => "Calendario", "permisos_correo" => "Correo", + "permisos_paises" => "Paises", "permisos_presupuestos" => "Presupuestos", "permisos_presupuestomaquetacion" => "Maquetación", @@ -674,6 +675,7 @@ return [ "menu_configuration" => "Configuracion", "menu_calendario" => "Calendario", + "menu_paises" => "Paises", "menu_correo" => "Correo", "menu_formaspago" => "Metodos de pago", "menu_imposiciones" => "Imposiciones", diff --git a/ci4/app/Language/es/Paises.php b/ci4/app/Language/es/Paises.php index 8235db84..ed3b3d86 100644 --- a/ci4/app/Language/es/Paises.php +++ b/ci4/app/Language/es/Paises.php @@ -3,20 +3,52 @@ return [ - 'code' => 'Code', - 'code3' => 'Code3', + 'code' => 'Código', + 'code3' => 'Código33', 'id' => 'ID', 'keyErp' => 'Key Erp', 'moduleTitle' => 'Paises', 'moneda' => 'Moneda', 'nombre' => 'Nombre', - 'pais' => 'Pais', - 'paisList' => 'Pais List', + 'pais' => 'País', + 'paisList' => 'Lista Paises', 'paises' => 'Paises', - 'showErp' => 'Show Erp', + 'showErp' => 'Mostrar Erp', 'urlErp' => 'URL Erp', 'userErp' => 'User Erp', 'validation' => [ + 'code3' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'key_erp' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'url_erp' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'user_erp' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'moneda' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + 'required' => 'The {field} field is required.', + + ], + + 'nombre' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + 'required' => 'The {field} field is required.', + + ], + 'code' => [ 'is_unique' => 'The {field} field must contain a unique value', 'max_length' => 'The {field} field cannot exceed {param} characters in length.', @@ -27,61 +59,5 @@ return [ ], - 'validation' => [ - 'code3' => [ - 'max_length' => 'The {field} field cannot exceed {param} characters in length.', - - ], - - - ], - - 'validation' => [ - 'key_erp' => [ - 'max_length' => 'The {field} field cannot exceed {param} characters in length.', - - ], - - - ], - - 'validation' => [ - 'moneda' => [ - 'max_length' => 'The {field} field cannot exceed {param} characters in length.', - 'required' => 'The {field} field is required.', - - ], - - - ], - - 'validation' => [ - 'nombre' => [ - 'max_length' => 'The {field} field cannot exceed {param} characters in length.', - 'required' => 'The {field} field is required.', - - ], - - - ], - - 'validation' => [ - 'url_erp' => [ - 'max_length' => 'The {field} field cannot exceed {param} characters in length.', - - ], - - - ], - - 'validation' => [ - 'user_erp' => [ - 'max_length' => 'The {field} field cannot exceed {param} characters in length.', - - ], - - - ], - ]; \ No newline at end of file diff --git a/ci4/app/Models/Configuracion/PaisModel.php b/ci4/app/Models/Configuracion/PaisModel.php new file mode 100644 index 00000000..afb7844a --- /dev/null +++ b/ci4/app/Models/Configuracion/PaisModel.php @@ -0,0 +1,78 @@ + [ + "label" => "Paises.code", + "rules" => "trim|required|max_length[2]|is_unique[lg_paises.code,id,{id}]", + ], + "code3" => [ + "label" => "Paises.code3", + "rules" => "trim|max_length[3]", + ], + "key_erp" => [ + "label" => "Paises.keyErp", + "rules" => "trim|max_length[255]", + ], + "moneda" => [ + "label" => "Paises.moneda", + "rules" => "trim|required|max_length[3]", + ], + "nombre" => [ + "label" => "Paises.nombre", + "rules" => "trim|required|max_length[255]", + ], + "url_erp" => [ + "label" => "Paises.urlErp", + "rules" => "trim|max_length[255]", + ], + "user_erp" => [ + "label" => "Paises.userErp", + "rules" => "trim|max_length[255]", + ], + ]; + + protected $validationMessages = [ + "code" => [ + "is_unique" => "Paises.validation.code.is_unique", + "max_length" => "Paises.validation.code.max_length", + "required" => "Paises.validation.code.required", + ], + "code3" => [ + "max_length" => "Paises.validation.code3.max_length", + ], + "key_erp" => [ + "max_length" => "Paises.validation.key_erp.max_length", + ], + "moneda" => [ + "max_length" => "Paises.validation.moneda.max_length", + "required" => "Paises.validation.moneda.required", + ], + "nombre" => [ + "max_length" => "Paises.validation.nombre.max_length", + "required" => "Paises.validation.nombre.required", + ], + "url_erp" => [ + "max_length" => "Paises.validation.url_erp.max_length", + ], + "user_erp" => [ + "max_length" => "Paises.validation.user_erp.max_length", + ], + ]; +} diff --git a/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/_paisFormItems.php b/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/_paisFormItems.php new file mode 100644 index 00000000..9bfc0f4c --- /dev/null +++ b/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/_paisFormItems.php @@ -0,0 +1,66 @@ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ +
+ +
\ No newline at end of file diff --git a/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/viewPaisForm.php b/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/viewPaisForm.php new file mode 100644 index 00000000..5a5a91c5 --- /dev/null +++ b/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/viewPaisForm.php @@ -0,0 +1,26 @@ +include("themes/_commonPartialsBs/select2bs5") ?> +extend('themes/backend/focus2/main/defaultlayout') ?> + +section("content") ?> +
+
+
+
+

+
+
+ +
+ + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
+ +
+
+
+
+endSection() ?> diff --git a/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/viewPaisList.php b/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/viewPaisList.php new file mode 100644 index 00000000..d2a24027 --- /dev/null +++ b/ci4/app/Views/themes/backend/focus2/form/configuracion/paises/viewPaisList.php @@ -0,0 +1,84 @@ +include('themes/_commonPartialsBs/datatables') ?> +extend('themes/backend/focus2/main/defaultlayout') ?> + +section('content'); ?> +
+
+ +
+
+

+ 'btn btn-primary float-end']); ?> +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ id ?> + + nombre) || strlen($item->nombre) < 51 ? esc($item->nombre) : character_limiter(esc($item->nombre), 50) ?> + + code) ?> + + code3) ?> + + moneda) ?> + + url_erp) ?> + + user_erp) || strlen($item->user_erp) < 51 ? esc($item->user_erp) : character_limiter(esc($item->user_erp), 50) ?> + + key_erp) || strlen($item->key_erp) < 51 ? esc($item->key_erp) : character_limiter(esc($item->key_erp), 50) ?> + + + show_erp ) { ?> + + + + + + + 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('deletePais', $item->id), 'data-bs-toggle'=>'modal', 'data-bs-target'=>'#confirm2delete']); ?> +
+
+ +
+
+
+ +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/backend/focus2/main/menu.php b/ci4/app/Views/themes/backend/focus2/main/menu.php index 0cb8b2c1..4dcf3ef5 100644 --- a/ci4/app/Views/themes/backend/focus2/main/menu.php +++ b/ci4/app/Views/themes/backend/focus2/main/menu.php @@ -24,7 +24,7 @@ - +