diff --git a/ci4/app/Config/Email.php b/ci4/app/Config/Email.php
index e354e4f3..9447a491 100755
--- a/ci4/app/Config/Email.php
+++ b/ci4/app/Config/Email.php
@@ -48,7 +48,7 @@ class Email extends BaseConfig
/**
* SMTP Timeout (in seconds)
*/
- public int $SMTPTimeout = 5;
+ public int $SMTPTimeout = 15;
/**
* Enable persistent SMTP connections
diff --git a/ci4/app/Controllers/Soporte/Ticketcontroller.php b/ci4/app/Controllers/Soporte/Ticketcontroller.php
index 0c732ffb..44a5386d 100644
--- a/ci4/app/Controllers/Soporte/Ticketcontroller.php
+++ b/ci4/app/Controllers/Soporte/Ticketcontroller.php
@@ -58,14 +58,14 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
return view(static::$viewPath . 'viewTicketList', $viewData);
}
- private function sendMail($subject,$body,$recipient)
+ private function sendMail($subject, $body, $recipient)
{
$settings_model = new SettingsModel();
$config = $settings_model->first()->toArray();
$gateway = $config['email_gateway'];
$body = html_entity_decode($body);
- if($gateway == 'smtp'){
+ if ($gateway == 'smtp') {
try {
//https://codeigniter.com/user_guide/libraries/email.html
$email = \Config\Services::email();
@@ -74,23 +74,22 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$config['SMTPUser'] = $config['email_address'];
$config['SMTPPass'] = $config['email_pass'];
$config['SMTPPort'] = intval($config['email_port']);
- $config['SMTPCrypto'] = $config['email_cert']=='none'?'':$config['email_cert'];
+ $config['SMTPCrypto'] = $config['email_cert'] == 'none' ? '' : $config['email_cert'];
$config['SMTPTimeout'] = 15;
$config['mailType'] = 'html';
$config['wordWrap'] = true;
$email->initialize($config);
- $email->setFrom($config['email_address'], $config['email_name']);
+ $email->setFrom($config['email_address'], $config['email_name']);
$email->setTo($recipient);
$email->setSubject($subject);
$email->setMessage($body);
- if (!$email->send())
- {
+ if (!$email->send()) {
return false;
- }else{
+ } else {
return true;
}
} catch (\Exception $ex) {
@@ -105,7 +104,7 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
//checkPermission('tickets.create', $this->indexRoute);
- if ($this->request->getPost()) :
+ if ($this->request->getPost()):
$nullIfEmpty = false; // !(phpversion() >= '8.1');
@@ -118,10 +117,10 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$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)->save($sanitizedData);
} catch (\Exception $e) {
@@ -135,7 +134,7 @@ class Ticketcontroller 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();
@@ -145,10 +144,10 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$userModel = new \App\Models\UserModel();
- $this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['supportUser'])->email);
+ $this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['user_soporte_id'])->email);
- if ($thenRedirect) :
- if (!empty($this->indexRoute)) :
+ if ($thenRedirect):
+ if (!empty($this->indexRoute)):
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
else:
return $this->redirect2listView('successMessage', $message);
@@ -181,51 +180,63 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
{
$modelRespuesta = new \App\Models\Soporte\TicketRespuestaModel();
- if ($requestedId == null) :
+ if ($requestedId == null):
return $this->redirect2listView();
endif;
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$ticket = $this->model->find($id);
- if ($ticket == false) :
+ if ($ticket == false):
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tickets.ticket')), $id]);
return $this->redirect2listView('errorMessage', $message);
endif;
- if(!auth()->user()->can('Tickets.edit') && auth()->user()->id != $ticket->usuario_id){
+ if (!auth()->user()->can('Tickets.edit') && auth()->user()->id != $ticket->usuario_id) {
return redirect()->to(route_to('TicketIndex'))->with('errorMessage', lang('Basic.global.noPermission'));
}
- if ($this->request->getPost()) :
+ if ($this->request->getPost()):
+
+ $oldUserSupport = $ticket->user_soporte_id;
+ $oldState = $ticket->estado_id;
$postData = $this->request->getPost();
- $sanitizedData = $this->sanitized($postData, false);
+ $sanitizedData = $this->sanitized($postData, false);
$noException = true;
- if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
- if ($this->canValidate()) :
+ if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
+ if ($this->canValidate()):
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
$this->saveImages($id, $this->request->getFiles());
- if(auth()->user()->can('Tickets.edit')){
+ if (auth()->user()->can('Tickets.edit')) {
- $respuesta = $modelRespuesta->where('ticket_id', $id)->first();
- if($respuesta == null){
+ $respuesta = $modelRespuesta->where('ticket_id', $id)->first();
+ if ($respuesta == null) {
$modelRespuesta->insert([
'ticket_id' => $id,
'usuario_id' => auth()->user()->id,
'mensaje' => $sanitizedData['respuesta_mensaje']
]);
- }else{
+ } else {
$modelRespuesta->update($respuesta->id, [
'mensaje' => $sanitizedData['respuesta_mensaje'],
'usuario_id' => auth()->user()->id,
]);
}
-
+ // envio de correos
+ $userModel = new \App\Models\UserModel();
+ if ($oldUserSupport != $sanitizedData['supportUser']) {
+ $this->sendMail(lang('Tickets.asgignToChanged'), lang('Tickets.asgignToChangedBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['supportUser'])->email);
+ }
+
+ if ($oldState != $sanitizedData['estado_id']) {
+ $this->sendMail(lang('Tickets.stateChange'), lang('Tickets.stateChangeBody') . base_url(route_to('editTicket', $id)), $userModel->find($ticket->usuario_id)->email);
+ }
+
}
} catch (\Exception $e) {
@@ -242,12 +253,12 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$thenRedirect = false;
endif;
- if ($noException && $successfulResult) :
+ if ($noException && $successfulResult):
$id = $ticket->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('successMessage', $message);
else:
return $this->redirect2listView('successMessage', $message);
@@ -295,9 +306,9 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$searchValues = get_filter_datatables_columns($reqData);
- if(auth()->user()->can('tickets.edit')){
+ if (auth()->user()->can('tickets.edit')) {
$user_id = null;
- }else{
+ } else {
$user_id = auth()->user()->id;
}
@@ -359,9 +370,9 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
// Guardar en la base de datos
$fileModel->insert([
'nombre' => $originalName,
- 'ticket_id' => $ticket_id,
- 'hash' => $fileHash,
- 'path' => 'uploads/tickets/' . $newFileName
+ 'ticket_id' => $ticket_id,
+ 'hash' => $fileHash,
+ 'path' => 'uploads/tickets/' . $newFileName
]);
}
}
diff --git a/ci4/app/Language/es/Tickets.php b/ci4/app/Language/es/Tickets.php
index 2cd8e9a8..15e10bdc 100644
--- a/ci4/app/Language/es/Tickets.php
+++ b/ci4/app/Language/es/Tickets.php
@@ -49,5 +49,9 @@ return [
// Mail
'newTicket' => 'Nuevo Ticket en ERP Safekat',
+ 'stateChange' => 'Cambio de estado en ticket en ERP Safekat',
+ 'asgignToChanged' => 'Asignado ticket en ERP Safekat',
'newTicketBody' => '
Se ha creado un nuevo ticket en el sistema de soporte de Safekat ERP.
Puede verlo en el siguiente enlace:
',
+ 'stateChangeBody' => 'El estado de un ticket en el sistema de soporte de Safekat ERP ha cambiado.
Puede verlo en el siguiente enlace:
',
+ 'asgignToChangedBody' => 'Se le ha asignado un ticket en el sistema de soporte de Safekat ERP.
Puede verlo en el siguiente enlace:
',
];
diff --git a/ci4/app/Models/Soporte/TicketModel.php b/ci4/app/Models/Soporte/TicketModel.php
index 7860a6e6..b87441cf 100644
--- a/ci4/app/Models/Soporte/TicketModel.php
+++ b/ci4/app/Models/Soporte/TicketModel.php
@@ -8,7 +8,7 @@ class TicketModel extends \App\Models\BaseModel
protected $table = 'tickets';
protected $primaryKey = 'id';
- protected $allowedFields = ['usuario_id', 'user_soporte_id', 'seccion_id' ,'categoria_id', 'estado_id', 'prioridad', 'titulo', 'descripcion', 'created_at', 'updated_at'];
+ protected $allowedFields = ['usuario_id', 'user_soporte_id', 'seccion_id', 'categoria_id', 'estado_id', 'prioridad', 'titulo', 'descripcion', 'created_at', 'updated_at'];
protected $useTimestamps = true;
@@ -29,8 +29,8 @@ class TicketModel extends \App\Models\BaseModel
public function getEstados()
{
$values = $this->db->table('tickets_estados')->get()->getResultArray();
-
- for($i = 0; $i < count($values); $i++){
+
+ for ($i = 0; $i < count($values); $i++) {
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
}
@@ -40,8 +40,8 @@ class TicketModel extends \App\Models\BaseModel
public function getCategorias()
{
$values = $this->db->table('tickets_categorias')->get()->getResultArray();
-
- for($i = 0; $i < count($values); $i++){
+
+ for ($i = 0; $i < count($values); $i++) {
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
}
@@ -52,7 +52,7 @@ class TicketModel extends \App\Models\BaseModel
{
$values = $this->db->table('tickets_secciones')->get()->getResultArray();
- for($i = 0; $i < count($values); $i++){
+ for ($i = 0; $i < count($values); $i++) {
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
}
@@ -100,13 +100,44 @@ class TicketModel extends \App\Models\BaseModel
else {
$builder->groupStart();
foreach ($search as $col_search) {
- if ($col_search[0] > 0 && $col_search[0] < 4)
- $builder->where(self::SORTABLE[$col_search[0]], $col_search[2]);
+ if ($col_search[1] == "seccion_id") {
+ $id = $this->getIdFromKeyword("tickets_secciones", $col_search[2]);
+ $builder->where("t1." . $col_search[1], $id);
+ } else if ($col_search[1] == "categoria_id") {
+ $id = $this->getIdFromKeyword("tickets_categorias", $col_search[2]);
+ $builder->where("t1." . $col_search[1], $id);
+ } else if ($col_search[1] == "estado_id") {
+ $id = $this->getIdFromKeyword("tickets_estados", $col_search[2]);
+ $builder->where("t1." . $col_search[1], $id);
+ } else if ($col_search[1] == "prioridad") {
+ $builder->where("t1." . $col_search[1], $col_search[2]);
+ } else if ($col_search[1] == "created_at") {
+ $dates = explode(" ", $col_search[2]);
+ $builder->where("t1." . $col_search[1] . ">=", $dates[0]);
+ $builder->where("t1." . $col_search[1] . "<=", $dates[1]);
+ } else if ($col_search[1] == "usuario_id") {
+ $builder->like("t2.first_name", $col_search[2]);
+ $builder->orLike("t2.last_name", $col_search[2]);
+ } else if ($col_search[1] == "user_soporte_id") {
+ $builder->like("t6.first_name", $col_search[2]);
+ $builder->orLike("t6.last_name", $col_search[2]);
+ }
else
- $builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
+ $builder->like("t1." . $col_search[1], $col_search[2]);
}
$builder->groupEnd();
return $builder;
+
}
}
+
+ private function getIdFromKeyword($table, $keyword)
+ {
+ $subquery = $this->db->table($table)
+ ->select('id')
+ ->where('keyword', $keyword)
+ ->get()
+ ->getRow();
+ return $subquery->id;
+ }
}
diff --git a/ci4/app/Views/themes/vuexy/form/soporte/viewTicketList.php b/ci4/app/Views/themes/vuexy/form/soporte/viewTicketList.php
index a1d546f5..b022bbee 100644
--- a/ci4/app/Views/themes/vuexy/form/soporte/viewTicketList.php
+++ b/ci4/app/Views/themes/vuexy/form/soporte/viewTicketList.php
@@ -21,12 +21,16 @@
= lang('Tickets.tipo') ?> |
= lang('Tickets.seccion') ?> |
= lang('Tickets.estado') ?> |
- = lang('Tickets.prioridad') ?> |
+
+ = lang('Tickets.prioridad') ?> |
+
= lang('Tickets.asunto') ?> |
- = lang('Tickets.usuario') ?> |
- = lang('Tickets.asignarTo') ?> |
+
+ = lang('Tickets.usuario') ?> |
+ = lang('Tickets.asignarTo') ?> |
+
= lang('Tickets.fechaCreacion') ?> |
- = lang('Basic.global.Action') ?> |
+ = lang('Basic.global.Action') ?> |
@@ -45,6 +49,7 @@
= $this->section('css') ?>
">
+
= $this->endSection() ?>
@@ -65,6 +70,7 @@
crossorigin="anonymous" referrerpolicy="no-referrer">
+
= $this->endSection() ?>
diff --git a/httpdocs/assets/js/safekat/pages/soporte/tickets.js b/httpdocs/assets/js/safekat/pages/soporte/tickets.js
index 9bdfc789..c442772f 100644
--- a/httpdocs/assets/js/safekat/pages/soporte/tickets.js
+++ b/httpdocs/assets/js/safekat/pages/soporte/tickets.js
@@ -38,55 +38,81 @@ class Ticket {
#initDatatable() {
- this.#headerSearcher();
-
const self = this;
+ self.#headerSearcher();
+
const actions = ['view'];
- const columns = [
- { 'data': 'id' },
- {
- 'data': 'categoria_id',
- render: function (data, type, row) {
- return window.language.Tickets[row.categoria];
- }
- },
- {
- 'data': 'seccion_id',
- render: function (data, type, row) {
- return window.language.Tickets[row.seccion];
- }
- },
- {
- 'data': 'estado_id',
- render: function (data, type, row) {
- return window.language.Tickets[row.estado];
- }
- },
- {
- 'data': 'prioridad',
- render: function (data, type, row) {
- return window.language.Tickets[data];
+
+ let columns = [];
+ if (window.userType == 1) {
+ columns = [
+ { 'data': 'id' },
+ {
+ 'data': 'categoria_id',
+ render: function (data, type, row) {
+ return window.language.Tickets[row.categoria];
+ }
},
- visible: false,
- },
- { 'data': 'titulo' },
- {
- 'data': 'usuario_id',
- render: function (data, type, row) {
- return row.usuario;
+ {
+ 'data': 'seccion_id',
+ render: function (data, type, row) {
+ return window.language.Tickets[row.seccion];
+ }
},
- visible: false,
- },
- {
- 'data': 'user_soporte_id',
- render: function (data, type, row) {
- return row.user_soporte;
+ {
+ 'data': 'estado_id',
+ render: function (data, type, row) {
+ return window.language.Tickets[row.estado];
+ }
},
- visible: false,
- },
- { 'data': 'created_at' },
- ];
+ {
+ 'data': 'prioridad',
+ render: function (data, type, row) {
+ return window.language.Tickets[data];
+ },
+ },
+ { 'data': 'titulo' },
+ {
+ 'data': 'usuario_id',
+ render: function (data, type, row) {
+ return row.usuario;
+ },
+ },
+ {
+ 'data': 'user_soporte_id',
+ render: function (data, type, row) {
+ return row.user_soporte;
+ },
+ },
+ { 'data': 'created_at' },
+ ];
+ }
+ else {
+ columns = [
+ { 'data': 'id' },
+ {
+ 'data': 'categoria_id',
+ render: function (data, type, row) {
+ return window.language.Tickets[row.categoria];
+ }
+ },
+ {
+ 'data': 'seccion_id',
+ render: function (data, type, row) {
+ return window.language.Tickets[row.seccion];
+ }
+ },
+ {
+ 'data': 'estado_id',
+ render: function (data, type, row) {
+ return window.language.Tickets[row.estado];
+ }
+ },
+ { 'data': 'titulo' },
+ { 'data': 'created_at' },
+ ];
+ }
this.table = new Table(
@@ -103,17 +129,10 @@ class Ticket {
});
this.table.table.on('init.dt', function () {
- self.table.table.page.len(50).draw();
- if (window.userType == 1) {
- self.table.table.column(4).visible(true);
- self.table.table.column(6).visible(true);
- self.table.table.column(7).visible(true);
+ self.table.table.page.len(100).draw();
+ self.table.table.draw();
- self.table.table.column(4).header().style.display = 'table-cell';
- self.table.table.column(6).header().style.display = 'table-cell';
- self.table.table.column(7).header().style.display = 'table-cell';
- }
});
this.table.setEditCallback(function (id) {
@@ -124,11 +143,14 @@ class Ticket {
#headerSearcher() {
const self = this;
- $('#tableOfTickets thead tr').clone(true).appendTo('#tableOfTickets thead');
+ $('#tableOfTickets thead tr.search-header').remove();
+ let searchRow = $('#tableOfTickets thead tr').first().clone(true);
+ searchRow.addClass('search-header').appendTo('#tableOfTickets thead');
+
$('#tableOfTickets thead tr:eq(1) th').each(function (i) {
if (!$(this).hasClass("noFilter")) {
var title = $(this).text();
- if (i == 8) {
+ if (title == window.language.Tickets.fechaCreacion) {
$(this).html('');
var bsRangePickerRange = $('#bs-rangepicker-range')
@@ -142,13 +164,13 @@ class Ticket {
[window.language.datePicker.ultimoMes]: [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
opens: 'right',
- language: '= config('Basics')->i18n ?>',
+ language: $('html').attr('lang'),
"locale": {
- "customRangeLabel": "= lang('datePicker.personalizar') ?>",
+ "customRangeLabel": window.language.datePicker.personalizar,
"format": "YYYY-MM-DD",
"separator": " ",
- "applyLabel": "= lang('datePicker.aplicar') ?>",
- "cancelLabel": "= lang('datePicker.limpiar') ?>",
+ "applyLabel": window.language.datePicker.aplicar,
+ "cancelLabel": window.language.datePicker.limpiar,
},
"alwaysShowCalendars": true,
@@ -158,7 +180,7 @@ class Ticket {
bsRangePickerRange.on('apply.daterangepicker', function (ev, picker) {
$(this).val(picker.startDate.format('YYYY-MM-DD') + ' ' + picker.endDate.format('YYYY-MM-DD'));
- self.table
+ self.table.table
.column(i)
.search(this.value)
.draw();
@@ -166,14 +188,14 @@ class Ticket {
bsRangePickerRange.on('cancel.daterangepicker', function (ev, picker) {
$(this).val('');
- self.table
+ self.table.table
.column(i)
.search(this.value)
.draw();
});
}
- else if (i == 1) {
+ else if (title == window.language.Tickets.tipo) {
// Agregar un selector en la tercera columna
$(this).html('');
@@ -188,11 +210,11 @@ class Ticket {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
- self.table.column(i).search(val).draw();
+ self.table.table.column(i).search(val).draw();
});
}
- else if (i == 2) {
+ else if (title == window.language.Tickets.seccion) {
// Agregar un selector en la tercera columna
$(this).html('');
@@ -210,10 +232,10 @@ class Ticket {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
- self.table.column(i).search(val).draw();
+ self.table.table.column(i).search(val).draw();
});
}
- else if (i == 2) {
+ else if (title == window.language.Tickets.estado) {
// Agregar un selector en la tercera columna
$(this).html('');
@@ -223,15 +245,15 @@ class Ticket {
selectorEstado.append('');
selectorEstado.append('');
selectorEstado.append('');
-
+
selectorEstado.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
- self.table.column(i).search(val).draw();
+ self.table.table.column(i).search(val).draw();
});
}
- else if (i == 8) {
+ else if (title == window.language.Tickets.prioridad) {
// Agregar un selector en la tercera columna
$(this).html('');
@@ -241,20 +263,20 @@ class Ticket {
selectorPrioridad.append('');
selectorPrioridad.append('');
selectorPrioridad.append('');
-
+
selectorPrioridad.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
- self.table.column(i).search(val).draw();
+ self.table.table.column(i).search(val).draw();
});
}
else {
$(this).html('');
$('input', this).on('change clear', function () {
- if (self.table.column(i).search() !== this.value) {
- self.table
+ if (self.table.table.column(i).search() !== this.value) {
+ self.table.table
.column(i)
.search(this.value)
.draw();
@@ -273,7 +295,7 @@ document.addEventListener('DOMContentLoaded', function () {
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
- new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Tickets, datePicker'] }, {},
+ new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Tickets', 'datePicker'] }, {},
function (translations) {
window.language = JSON.parse(translations);
new Ticket();