empezada la estructura de tickets

This commit is contained in:
2025-02-14 12:14:23 +01:00
parent eea415fb47
commit b3cc82636d
11 changed files with 450 additions and 0 deletions

View File

@ -909,6 +909,22 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
});
$routes->group('messages', ['namespace' => 'App\Controllers\Chat'], function ($routes) {
$routes->get('datatable', 'ChatController::datatable_messages', ['as' => 'getDatatableMessages']);
$routes->get('datatable/presupuesto', 'ChatController::datatable_presupuesto_messages', ['as' => 'getDatatablePresupuestoMessages']);
$routes->get('datatable/pedido', 'ChatController::datatable_pedido_messages', ['as' => 'getDatatablePedidoMessages']);
$routes->get('datatable/factura', 'ChatController::datatable_factura_messages', ['as' => 'getDatatableFacturaMessages']);
$routes->post('direct', 'ChatController::store_new_direct_message', ['as' => 'storeNewDirectMessage']);
$routes->post('direct/client', 'ChatController::store_new_direct_message_client', ['as' => 'storeNewDirectMessageClient']);
});
$routes->group('soporte', ['namespace' => 'App\Controllers\Soporte'], function ($routes) {
$routes->get('', 'Ticketcontroller::index', ['as' => 'TicketIndex']);
$routes->get('add', 'Ticketcontroller::add', ['as' => 'NewTicket']);
});
$routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], function ($routes) {
$routes->group('ordentrabajo', ['namespace' => 'App\Controllers\Produccion'], function ($routes) {

View File

@ -0,0 +1,189 @@
<?php
namespace App\Controllers\Soporte;
use App\Models\TicketModel;
use App\Models\CategoriaModel;
use App\Models\EstadoModel;
use CodeIgniter\Controller;
use App\Entities\Soporte\TicketEntity;
class Ticketcontroller extends \App\Controllers\GoBaseController
{
protected static $primaryModelName = 'App\Models\Soporte\ticketModel';
protected static $singularObjectNameCc = 'ticket';
protected static $singularObjectName = 'Ticket';
protected static $pluralObjectName = 'Tickets';
protected static $controllerSlug = 'ticket';
protected static $viewPath = 'themes/vuexy/form/soporte/';
protected $indexRoute = 'TicketIndex';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Tickets.moduleTitle');
// Breadcrumbs
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_soporte"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("App.menu_ticket_list"), 'route' => route_to('TicketIndex'), 'active' => true]
];
parent::initController($request, $response, $logger);
}
public function index()
{
//checkPermission('tickets.menu');
$this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifaextra.tarifaextra')]);
parent::index();
}
public function add()
{
//checkPermission('tickets.create', $this->indexRoute);
if ($this->request->getPost()) :
$nullIfEmpty = false; // !(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', [lang('Basic.global.record')]);
$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', [lang('Basic.global.record')]) . '.';
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->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['ticketEntity'] = isset($sanitizedData) ? new TicketEntity($sanitizedData) : new TicketEntity();
$this->viewData['formAction'] = route_to('NewTicket');
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Tarifaextra.tarifaextra') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__);
} // end function add()
public function edit($requestedId = null)
{
/*
checkPermission('tarifa-extra.edit', $this->indexRoute);
if ($requestedId == null) :
return $this->redirect2listView();
endif;
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$tarifaextraEntity = $this->model->find($id);
if ($tarifaextraEntity == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tarifaextra.tarifaextra')), $id]);
return $this->redirect2listView('errorMessage', $message);
endif;
if ($this->request->getPost()) :
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, true);
// JJO
if (isset($this->model->user_updated_id)) {
$sanitizedData['user_updated_id'] = auth()->user()->id;
}
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = 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('Tarifaextra.tarifaextra'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifaextraEntity->fill($sanitizedData);
$thenRedirect = false;
endif;
if ($noException && $successfulResult) :
$id = $tarifaextraEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
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->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['tarifaextraEntity'] = $tarifaextraEntity;
$this->viewData['formAction'] = route_to('updateTarifaextra', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Tarifaextra.tarifaextra') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id);
*/
} // end function edit(...)
}

View File

@ -0,0 +1,80 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateTicketsSystem extends Migration
{
public function up()
{
// Tabla de Categorías
$this->forge->addField([
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'nombre' => ['type' => 'VARCHAR', 'constraint' => 100, 'unique' => true],
]);
$this->forge->addPrimaryKey('id');
$this->forge->createTable('categorias');
// Tabla de Estados
$this->forge->addField([
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'nombre' => ['type' => 'VARCHAR', 'constraint' => 100, 'unique' => true],
]);
$this->forge->addPrimaryKey('id');
$this->forge->createTable('estados');
// Tabla de Tickets
$this->forge->addField([
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'usuario_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'categoria_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'estado_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'prioridad' => ['type' => 'ENUM', 'constraint' => ['alta', 'media', 'baja'], 'default' => 'media'],
'titulo' => ['type' => 'VARCHAR', 'constraint' => 255],
'descripcion' => ['type' => 'TEXT'],
'created_at' => ['type' => 'DATETIME', 'null' => true],
'updated_at' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('usuario_id', 'users', 'id', 'CASCADE', 'CASCADE');
$this->forge->addForeignKey('categoria_id', 'categorias', 'id', 'CASCADE', 'CASCADE');
$this->forge->addForeignKey('estado_id', 'estados', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('tickets');
// Tabla de Respuestas
$this->forge->addField([
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'ticket_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'usuario_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'mensaje' => ['type' => 'TEXT'],
'created_at' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('ticket_id', 'tickets', 'id', 'CASCADE', 'CASCADE');
$this->forge->addForeignKey('usuario_id', 'users', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('respuestas');
// Tabla de Adjuntos
$this->forge->addField([
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'ticket_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
'respuesta_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
'archivo' => ['type' => 'VARCHAR', 'constraint' => 255],
'created_at' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('ticket_id', 'tickets', 'id', 'CASCADE', 'CASCADE');
$this->forge->addForeignKey('respuesta_id', 'respuestas', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('adjuntos');
}
public function down()
{
$this->forge->dropTable('adjuntos');
$this->forge->dropTable('respuestas');
$this->forge->dropTable('tickets');
$this->forge->dropTable('categorias');
$this->forge->dropTable('estados');
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace App\Entities\Soporte;
use CodeIgniter\Entity\Entity;
class TicketEntity extends Entity
{
protected $attributes = [
'id' => null,
'usuario_id' => null,
'tecnico_id' => null,
'categoria_id'=> null,
'estado_id' => null,
'prioridad' => 'media',
'titulo' => '',
'descripcion' => '',
'created_at' => null,
'updated_at' => null,
];
protected $dates = ['created_at', 'updated_at'];
public function setTitulo(string $titulo)
{
$this->attributes['titulo'] = ucfirst($titulo); // Capitaliza el título
return $this;
}
public function setDescripcion(string $descripcion)
{
$this->attributes['descripcion'] = ucfirst($descripcion);
return $this;
}
public function getPrioridad(): string
{
return ucfirst($this->attributes['prioridad']);
}
public function asignarTecnico(int $tecnicoId)
{
$this->attributes['tecnico_id'] = $tecnicoId;
return $this;
}
public function cambiarEstado(int $estadoId)
{
$this->attributes['estado_id'] = $estadoId;
return $this;
}
}

View File

@ -818,5 +818,9 @@ return [
"menu_oauth" => "Autenticaciones",
"menu_template" => "Plantillas",
"menu_soporte" => "Soporte",
"menu_soporte_new_ticket" => "Crear ticket",
"menu_soporte_ticket_list" => "Mis tickets",
];

View File

@ -0,0 +1,9 @@
<?php
return [
'ticket' => 'Ticket',
'tickets' => 'Tickets',
'moduleTitle' => 'Tickets',
];

View File

@ -0,0 +1,26 @@
<?php
namespace App\Models\Soporte;
class TicketModel extends \App\Models\BaseModel
{
protected $table = 'tickets';
protected $primaryKey = 'id';
protected $allowedFields = ['usuario_id', 'tecnico_id', 'categoria_id', 'estado_id', 'prioridad', 'titulo', 'descripcion', 'created_at', 'updated_at'];
protected $useTimestamps = true;
public function getTickets($id = null)
{
if ($id === null) {
return $this->select('tickets.*, users.nombre as usuario, categorias.nombre as categoria, estados.nombre as estado')
->join('users', 'users.id = tickets.usuario_id')
->join('categorias', 'categorias.id = tickets.categoria_id')
->join('estados', 'estados.id = tickets.estado_id')
->findAll();
}
return $this->find($id);
}
}

View File

@ -0,0 +1,50 @@
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
<?=$this->extend('themes/vuexy/main/defaultlayout') ?>
<?=$this->section('content'); ?>
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h4>Crear Ticket</h4>
</div>
<div class="card-body">
<form action="<?= base_url('tickets/crear'); ?>" method="post">
<?= csrf_field(); ?>
<div class="mb-3">
<label class="form-label">Título</label>
<input type="text" name="titulo" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Descripción</label>
<textarea name="descripcion" class="form-control" rows="4" required></textarea>
</div>
<div class="mb-3">
<label class="form-label">Categoría</label>
<select name="categoria_id" class="form-control">
<?php /*foreach ($categorias as $categoria): ?>
<option value="<?= $categoria['id']; ?>"><?= $categoria['nombre']; ?></option>
<?php endforeach;*/ ?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Prioridad</label>
<select name="prioridad" class="form-control">
<option value="alta">Alta</option>
<option value="media" selected>Media</option>
<option value="baja">Baja</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Crear Ticket</button>
</form>
</div>
</div>
</div>
</div>
<?= $this->endSection(); ?>

View File

@ -48,6 +48,8 @@
require "menus/mensajes_menu.php";
require "menus/soporte_menu.php";
require "menus/sistema_menu.php";
?>

View File

@ -0,0 +1,22 @@
<!-- Soporte -->
<li class="menu-item">
<a href="javascript:void(0);" class="menu-link menu-toggle">
<i class="menu-icon tf-icons ti ti-users"></i>
<?= lang("App.menu_soporte") ?>
</a>
<ul class="menu-sub">
<li class="menu-item">
<a href="<?= route_to("NewTicket") ?>" class="menu-link">
<?= lang("App.menu_soporte_new_ticket") ?>
</a>
</li>
<li class="menu-item">
<a href="<?= route_to("TicketList") ?>" class="menu-link">
<?= lang("App.menu_soporte_ticket_list") ?>
</a>
</li>
</ul>
</li>