terminado

This commit is contained in:
2025-02-19 21:35:55 +01:00
parent fea409b5ad
commit b6decf8657
6 changed files with 195 additions and 121 deletions

View File

@ -48,7 +48,7 @@ class Email extends BaseConfig
/**
* SMTP Timeout (in seconds)
*/
public int $SMTPTimeout = 5;
public int $SMTPTimeout = 15;
/**
* Enable persistent SMTP connections

View File

@ -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
]);
}
}

View File

@ -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' => '<p>Se ha creado un nuevo ticket en el sistema de soporte de Safekat ERP. <br><br>Puede verlo en el siguiente enlace:</p>',
'stateChangeBody' => '<p>El estado de un ticket en el sistema de soporte de Safekat ERP ha cambiado. <br><br>Puede verlo en el siguiente enlace:</p>',
'asgignToChangedBody' => '<p>Se le ha asignado un ticket en el sistema de soporte de Safekat ERP. <br><br>Puede verlo en el siguiente enlace:</p>',
];

View File

@ -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;
}
}

View File

@ -21,12 +21,16 @@
<th><?= lang('Tickets.tipo') ?></th>
<th><?= lang('Tickets.seccion') ?></th>
<th><?= lang('Tickets.estado') ?></th>
<th style="display: none;"><?= lang('Tickets.prioridad') ?></th>
<?php if ($userType == 1) : ?>
<th><?= lang('Tickets.prioridad') ?></th>
<?php endif; ?>
<th><?= lang('Tickets.asunto') ?></th>
<th style="display: none;"><?= lang('Tickets.usuario') ?></th>
<th style="display: none;"><?= lang('Tickets.asignarTo') ?></th>
<?php if ($userType == 1) : ?>
<th><?= lang('Tickets.usuario') ?></th>
<th><?= lang('Tickets.asignarTo') ?></th>
<?php endif; ?>
<th><?= lang('Tickets.fechaCreacion') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
<th class="text-nowrap noFilter"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
@ -45,6 +49,7 @@
<?= $this->section('css') ?>
<link rel="stylesheet"
href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.css') ?>" />
<?= $this->endSection() ?>
@ -65,6 +70,7 @@
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.colVis.min.js") ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.js') ?>"></script>
<script type="module" src="<?= site_url('assets/js/safekat/pages/soporte/tickets.js') ?>"></script>
<?= $this->endSection() ?>

View File

@ -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('<input id="bs-rangepicker-range" type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
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('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -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('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -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('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -223,15 +245,15 @@ class Ticket {
selectorEstado.append('<option value="abierto">' + window.language.Tickets.abierto + '</option>');
selectorEstado.append('<option value="en_proceso">' + window.language.Tickets.en_proceso + '</option>');
selectorEstado.append('<option value="resuelto">' + window.language.Tickets.resuelto + '</option>');
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('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -241,20 +263,20 @@ class Ticket {
selectorPrioridad.append('<option value="baja">' + window.language.Tickets.baja + '</option>');
selectorPrioridad.append('<option value="media">' + window.language.Tickets.media + '</option>');
selectorPrioridad.append('<option value="baja">' + window.language.Tickets.alta + '</option>');
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 type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
$('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();