diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php
index 24000dc9..34182efa 100755
--- a/ci4/app/Config/Routes.php
+++ b/ci4/app/Config/Routes.php
@@ -66,6 +66,7 @@ $routes->group('users', ['namespace' => 'App\Controllers\Configuracion'], functi
$routes->get('delete/(:num)', 'Users::delete/$1', ['as' => 'deleteUser']);
$routes->post('allmenuitems', 'Users::allItemsSelect', ['as' => 'select2ItemsOfUsers']);
$routes->post('menuitems', 'Users::menuItems', ['as' => 'menuItemsOfUsers']);
+ $routes->post('getMenuComerciales', 'Users::getMenuComerciales', ['as' => 'menuItemsComerciales']);
});
$routes->group('group', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) {
@@ -354,10 +355,10 @@ $routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function
$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']);
+ $routes->post('datatable', 'ClientePrecios::datatable', ['as' => 'dataTableOfClienteprecios']);
+ $routes->post('datatable_editor', 'ClientePrecios::datatable_editor', ['as' => 'editorOfClienteprecios']);
});
-$routes->resource('clienteprecios', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Clienteprecios', 'except' => 'show,new,create,update']);
+$routes->resource('clienteprecios', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'ClientePrecios', 'except' => 'show,new,create,update']);
$routes->group('clienteplantillaprecios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) {
diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php
index cba6109d..455c78ec 100755
--- a/ci4/app/Controllers/Configuracion/Users.php
+++ b/ci4/app/Controllers/Configuracion/Users.php
@@ -67,7 +67,7 @@ class Users extends \App\Controllers\GoBaseController {
$currentGroups = $postData['group']??[];
unset($postData['group']);
-
+ $postData['username'] = strstr($postData['email'], '@', true);
$sanitizedData = $this->sanitized($postData, true);
$noException = true;
@@ -75,20 +75,28 @@ class Users extends \App\Controllers\GoBaseController {
$users = auth()->getProvider();
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
-
- if ($this->canValidate()) :
+ if ($this->canValidate()) :
try {
$user = new User([
- 'username' => strstr($sanitizedData['email'], '@', true),
+ 'username' => $sanitizedData['username'],
+ 'first_name' => $sanitizedData['first_name'],
+ 'last_name' => $sanitizedData['last_name'],
'email' => $sanitizedData['email'],
'password' => 'Safekat2024',
+ 'status' => $sanitizedData['status']??0,
+ 'active' => $sanitizedData['active']??0,
]);
$users->save($user);
- $successfulResult = true; // Hacked
+ $successfulResult = true; // Hacked
} catch (\Exception $e) {
$noException = false;
- $this->dealWithException($e);
+ //$this->dealWithException($e);
+ if (strpos($e->getMessage(), 'correo duplicado') !== false) {
+ $this->viewData['errorMessage'] = "El correo electrónico ya está registrado en el sistema";
+ $this->session->setFlashdata('formErrors', $this->model->errors());
+ }
+
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Users.user'))]);
@@ -100,10 +108,10 @@ class Users extends \App\Controllers\GoBaseController {
if ($noException && $successfulResult) :
$id = $users->getInsertID();
- $this->group_user_model->where('user_id', $user->id)->delete();
+ $this->group_user_model->where('user_id', $id)->delete();
foreach($currentGroups as $group){
$group_user_data = [
- 'user_id' => $user->id,
+ 'user_id' => $id,
'group' => $group
];
$this->group_user_model->insert($group_user_data);
@@ -296,6 +304,22 @@ class Users extends \App\Controllers\GoBaseController {
}
}
+ public function getMenuComerciales(){
+ if ($this->request->isAJAX()) {
+ $comerciales = $this->model->getComerciales();
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'menu' => $comerciales,
+ $csrfTokenName => $newTokenHash
+ ];
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
protected function getPaisListItems() {
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Pais.pais'))])];
diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php
index 96d2ca92..18ead92b 100644
--- a/ci4/app/Models/UserModel.php
+++ b/ci4/app/Models/UserModel.php
@@ -19,11 +19,27 @@ class UserModel extends ShieldUserModel
];
}
- /*protected $validationRules = [
- "email" => [
- "label" => "RolesPermisos.email",
- "rules" => "required|max_length[150]",
+ protected $validationRules = [
+ "username" => [
+ "label" => "correo duplicado",
+ "rules" => "is_unique[users.username]",
]
- ];*/
+ ];
+
+ public function getComerciales(){
+
+ $builder = $this->db
+ ->table("users" . " t1")
+ ->select(
+ "t1.id AS id, CONCAT(t1.first_name, ' ', t1.last_name) AS text"
+ );
+
+ $builder->where('t1.deleted_at', null);
+ $builder->where("t2.group", "comercial");
+ $builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left");
+
+ return $builder->get()->getResult();
+
+ }
}
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 6a488651..03ddbcd9 100644
--- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php
+++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php
@@ -1513,7 +1513,7 @@ function delete_direccion_envio(dataId){
=$this->section('css') ?>
">
- ">
+ ">
=$this->endSection() ?>
= $this->section('additionalExternalJs') ?>
diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php
index 6d5cabf2..ca21d53f 100644
--- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php
+++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php
@@ -55,7 +55,7 @@
$('#soporteId').select2({
allowClear: false,
ajax: {
- url: '= route_to("menuItemsOfUsers") ?>',
+ url: '= route_to("menuItemsComerciales") ?>',
type: 'post',
dataType: 'json',
@@ -200,14 +200,14 @@
$('#comercialId').select2({
allowClear: false,
ajax: {
- url: '= route_to("menuItemsOfUsers") ?>',
+ url: '= route_to("menuItemsComerciales") ?>',
type: 'post',
dataType: 'json',
data: function (params) {
return {
- id: 'id_user',
- text: 'first_name',
+ id: 'id',
+ text: 'text',
searchTerm: params.term,
= csrf_token() ?? "token" ?> : = csrf_token() ?>v
};