Merge branch 'maquinista-change-user' into 'main'

Maquinista change user

See merge request jjimenez/safekat!747
This commit is contained in:
Alvaro
2025-04-27 16:54:35 +00:00
12 changed files with 200 additions and 15 deletions

View File

@ -40,6 +40,8 @@ foreach (glob(APPPATH . 'Config/Routes/*Routes.php') as $routeFile) {
$routes->group('users', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) {
$routes->get('', 'Users::index', ['as' => 'userList']);
$routes->get('maquinista/change/user','Users::index_maquinista_change_user',['as' => 'maquinistaUserChangeList']);
$routes->get('maquinista/change/session/(:num)','Users::change_user_session/$1',['as' => 'maquinistaChangeUserSession']);
$routes->get('list', 'Users::index', ['as' => 'userList2']);
$routes->get('add', 'Users::add', ['as' => 'newUser']);
$routes->post('add', 'Users::add', ['as' => 'createUser']);
@ -642,6 +644,7 @@ $routes->group('messages', ['namespace' => 'App\Controllers\Chat'], function ($r
$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->get('datatable/ots', 'ChatController::datatable_ot_messages', ['as' => 'getDatatableOtMessages']);
$routes->post('direct', 'ChatController::store_new_direct_message', ['as' => 'storeNewDirectMessage']);
$routes->post('direct/client', 'ChatController::store_new_direct_message_client', ['as' => 'storeNewDirectMessageClient']);
@ -652,6 +655,8 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
$routes->get('presupuesto/(:num)', 'ChatController::get_chat_presupuesto_view/$1', ['as' => 'getChatPresupuestoView']);
$routes->get('pedido/(:num)', 'ChatController::get_chat_pedido_view/$1', ['as' => 'getChatPedidoView']);
$routes->get('factura/(:num)', 'ChatController::get_chat_factura_view/$1', ['as' => 'getChatFacturaView']);
$routes->get('ot/(:num)', 'ChatController::get_chat_ot_view/$1', ['as' => 'getChatOtView']);
$routes->get('direct/conversation/(:num)', 'ChatController::get_chat_direct/$1', ['as' => 'getChatDirect']);
$routes->get('direct/users/select/(:num)', 'ChatController::get_chat_direct_select_users/$1', ['as' => 'getChatDirectSelectUsers']);

View File

@ -222,6 +222,25 @@ class ChatController extends BaseController
return view(static::$viewPath . 'messageChatInternal', $this->viewData);
}
}
public function get_chat_ot_view($chat_id)
{
$chat = $this->chatModel->find($chat_id);
$this->viewData['breadcrumb'] = [
['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false],
['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true]
];
$this->viewData["modelId"] = $chat->orden_trabajo_id;
$this->viewData["type"] = "ot";
$auth_user = auth()->user();
$this->chatModel->setAsViewedChatUserNotifications($chat_id, $auth_user->id);
$this->chatModel->setAsUnviewedChatUserMessages($chat_id, $auth_user->id);
if ($chat->chat_department_id) {
return view(static::$viewPath . 'messageChatFactura', $this->viewData);
} else {
return view(static::$viewPath . 'messageChatInternal', $this->viewData);
}
}
public function get_chat(int $chat_id)
{
@ -502,6 +521,23 @@ class ChatController extends BaseController
->toJson(true);
}
public function datatable_ot_messages()
{
$auth_user_id = auth()->user()->id;
$isAdmin = auth()->user()->inGroup('admin');
$query = $this->chatModel->getQueryDatatableMessageOrdenTrabajo($auth_user_id);
return DataTable::of($query)
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
->edit('updated_at', fn($q) => $q->updated_at ? Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i") : "")
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
->add("action", fn($q) => ["type" => "ot", "modelId" => $q->id, "isAdmin" => $isAdmin,"chatMessageId" => $q->chatMessageId, "lang" => [
"view_chat" => lang('Chat.view_chat'),
"view_by_alt_message" => lang('Chat.view_by_alt_message')
]])
->toJson(true);
}
public function get_notifications_not_viewed_from_message(int $chat_message_id)
{
$unviewedNotifications = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_message_id);

View File

@ -1,4 +1,6 @@
<?php namespace App\Controllers\Configuracion;
<?php
namespace App\Controllers\Configuracion;
use App\Entities\Usuarios\UserEntity;
use App\Models\Chat\ChatDeparmentModel;
@ -54,7 +56,6 @@ class Users extends \App\Controllers\GoBaseController
];
parent::initController($request, $response, $logger);
}
public function index()
@ -87,7 +88,7 @@ class Users extends \App\Controllers\GoBaseController
// Marcar el username como NULL
$sanitizedData = $this->sanitized($postData, true);
$noException = true;
// Obtener proveedor de usuarios
@ -118,11 +119,10 @@ class Users extends \App\Controllers\GoBaseController
} // Email is not unique!
else {
$this->viewData['errorMessage'] = "El correo '". $sanitizedData['email'] ."' ya está registrado en el sistema";
$this->viewData['errorMessage'] = "El correo '" . $sanitizedData['email'] . "' ya está registrado en el sistema";
$this->session->setFlashdata('formErrors', $this->model->errors());
$successfulResult = false; // Hacked
}
} catch (\Exception $e) {
$noException = false;
$this->viewData['errorMessage'] = $e->getMessage();
@ -234,7 +234,6 @@ class Users extends \App\Controllers\GoBaseController
} else {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
}
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
@ -319,8 +318,6 @@ class Users extends \App\Controllers\GoBaseController
$message = "Usuario eliminado correctamente";
return $this->redirect2listView('successMessage', $message);
} // end function delete(...)
@ -374,9 +371,10 @@ class Users extends \App\Controllers\GoBaseController
}
}
public function datatable(){
public function datatable()
{
if($this->request->isAJAX()){
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
@ -405,7 +403,6 @@ class Users extends \App\Controllers\GoBaseController
$this->model->getResource([])->countAllResults(),
$this->model->getResource($searchValues)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
@ -447,4 +444,27 @@ class Users extends \App\Controllers\GoBaseController
return $data;
}
public function index_maquinista_change_user()
{
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_change_session"), 'route' => route_to('maquinistaUserChangeList'), 'active' => true]
];
$maquinistas = [];
$users = auth()->getProvider()->whereNotIn('id',[auth()->user()->id])->findAll();
foreach ($users as $key => $user) {
if ($user->inGroup('maquina') && !$user->inGroup('admin', 'comercial', 'cliente-editor', 'cliente-admin')) {
$maquinistas[] = $user;
}
}
$this->viewData['maquinistas'] = $maquinistas;
return view('/themes/vuexy/form/produccion/maquinista/viewMaquinistaCambioUserList.php', $this->viewData);
}
public function change_user_session(int $user_id)
{
// Check the credentials
$user = auth()->getProvider()->findById($user_id);
auth()->logout();
auth()->login($user);
return redirect("home");
}
}

View File

@ -105,11 +105,11 @@ class Ordentrabajo extends BaseController
public function update_orden_trabajo_tarea()
{
$bodyData = $this->request->getPost();
return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "data" => $bodyData]);
$validated = $this->validation->run($bodyData, "orden_trabajo_tarea");
if ($validated) {
$r = $this->produccionService->updateOrdenTrabajoTarea($bodyData["orden_trabajo_tarea_id"], $bodyData);
return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "data" => $bodyData]);
$tareaEntity = $this->otTarea->find($bodyData["orden_trabajo_tarea_id"]);
return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "data" => $tareaEntity]);
} else {
return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400);
}

View File

@ -761,6 +761,7 @@ return [
"menu_tarifaimpresion" => "Printing",
"menu_users" => "Users",
"menu_change_session" => "Seleccionar turno",
"menu_permission_group" => "Roles and permissions",
"menu_registration" => "Registration",

View File

@ -12,7 +12,7 @@
</div>
<div class="col-md-6 mb-2">
<p class="mb-0">Clicks</p>
<h4 class="mb-0" id="clicks-info"><?= $ot_tarea->click_tarea ?></h4>
<h4 class="mb-0" id="clicks-info"><?= $ot_tarea->click_end - $ot_tarea->click_init ?></h4>
</div>
</div>

View File

@ -26,6 +26,9 @@ use Config\App;
<li class="nav-item">
<button type="button" class="nav-link" role="tab" id="navs-top-align-facturas-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-facturas"><?=lang('App.menu_facturas')?></button>
</li>
<li class="nav-item">
<button type="button" class="nav-link" role="tab" id="navs-top-align-ot-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-ots"><?=lang('Produccion.ots')?></button>
</li>
</ul>
<div class="tab-content" id="message-datatables-container">
@ -41,7 +44,9 @@ use Config\App;
</div>
<div class="tab-pane fade show" id="navs-top-align-facturas">
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tableFacturaMessages"]) ?>
</div>
<div class="tab-pane fade show" id="navs-top-align-ots">
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tableOtMessages"]) ?>
</div>
</div>
<!--//.card -->

View File

@ -0,0 +1,63 @@
<?= $this->include('themes/_commonPartialsBs/select2bs5') ?>
<?= $this->include('themes/_commonPartialsBs/datatables') ?>
<?= $this->include('themes/_commonPartialsBs/sweetalert') ?>
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
<?= $this->section('content'); ?>
<!--Content Body-->
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table-maquinista table table-hover text-dark" style="width: 100%;">
<thead>
<tr>
<th><?= lang('ID') ?></th>
<th><?= lang('Users.firstName') ?></th>
<th><?= lang('Users.lastName') ?></th>
<th><?= lang('Users.email') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
<?php if (count($maquinistas) > 0): ?>
<?php foreach ($maquinistas as $key => $maquinista): ?>
<tr>
<td><?= $maquinista->id ?></td>
<td><?= $maquinista->first_name ?></td>
<td><?= $maquinista->last_name ?></td>
<td><?= $maquinista->getEmail() ?></td>
<td style="color: white;">
<a type="button" href="<?= route_to("maquinistaChangeUserSession", $maquinista->id) ?>" class="btn btn-lg btn-primary h-100 w-100">Mi turno</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr class="text-center">
<td colspan="5">No hay usuarios para cambiar turno</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?= $this->endSection() ?>
<?= $this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/maquinista.css') ?>" />
<?= $this->endSection() ?>
<?= $this->section("additionalExternalJs") ?>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
<?= $this->endSection() ?>

View File

@ -110,6 +110,17 @@ $picture = "/assets/img/default-user.png";
<i class="ti ti-menu-2 ti-sm"></i>
</a>
</div>
<!-- CAMBIO DE USUARIO PARA MAQUINISTA -->
<?php if (auth()->user()->inGroup('maquina')): ?>
<div class="navbar-nav-left d-flex align-items-center" id="navbar-collapse">
<ul class="navbar-nav flex-row justify-content-start align-items-center ms-auto">
<li class="nav-item dropdown-shortcuts navbar-dropdown dropdown me-2 me-xl-0">
<a type="btn" href="<?= route_to('maquinistaUserChangeList') ?>" class="btn btn-outline-primary btn-sm w-100">Cambiar usuario</a>
</li>
</ul>
</div>
<?php endif; ?>
<div class="navbar-nav-right d-flex align-items-center" id="navbar-collapse">
<ul class="navbar-nav flex-row align-items-center ms-auto">

View File

@ -7,6 +7,8 @@ class MessagesDatatable {
this.datatablePresupuestoMessageItem = this.item.find("#tablePresupuestoMessages")
this.datatablePedidoMessageItem = this.item.find("#tablePedidoMessages")
this.datatableFacturaMessageItem = this.item.find("#tableFacturaMessages")
this.datatableOtMessageItem = this.item.find("#tableOtMessages")
this.focusTable = this.datatableItem
this.columnDefs = [
]
@ -131,6 +133,25 @@ class MessagesDatatable {
columns: this.datatableColumns,
ajax: '/messages/datatable/factura'
});
this.datatableOtMessage = this.datatableOtMessageItem.DataTable({
processing: true,
order: [[1, 'desc']],
columnDefs : this.columnDefs,
orderCellsTop : true,
layout: {
topStart: 'pageLength',
topEnd: 'search',
bottomStart: 'info',
bottomEnd: 'paging'
},
serverSide: true,
pageLength: 10,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: this.datatableColumns,
ajax: '/messages/datatable/ots'
});
this.datatablePresupuestoMessageItem.on("keyup", ".datatable-message-filter", (event) => {
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
this.datatablePresupuestoMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
@ -143,6 +164,10 @@ class MessagesDatatable {
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
this.datatableFacturaMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
})
this.datatableOtMessageItem.on("keyup", ".datatable-message-filter", (event) => {
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
this.datatableFacturaMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
})
}

View File

@ -79,10 +79,14 @@ class MaquinistaTareaView {
}
handleUpdateClickInputSucess(response) {
popSuccessAlert(response.message)
this.updateContentClick(response.data.click_end - response.data.click_init)
}
handleUpdateClickInputError(error) {
popErrorAlert(error)
}
updateContentClick(clicks){
this.item.find('#clicks-info').empty().html(clicks)
}
handleDeleteTareaProgress() {
let ajax = new Ajax('/produccion/ordentrabajo/tarea/progress/' + this.tareaId,
null,
@ -194,6 +198,17 @@ class MaquinistaTareaView {
}
})
}
getTarea(tarea_id) {
return new Promise((resolve, reject) => {
let ajax = new Ajax(`/produccion/ordentrabajo/tarea/${tarea_id}`, null, null, (response) => {
resolve(response)
},
(error) => {
resolve(error)
})
ajax.get()
})
}
}

View File

@ -54,6 +54,10 @@ class MessagePage {
this.messageDatatable.datatableFacturaMessage.ajax.reload()
this.messageDatatable.focusTable = this.messageDatatable.datatableFacturaMessageItem
})
$("#navs-top-align-ot-tab").on("click",()=>{
this.messageDatatable.datatableOtMessage.ajax.reload()
this.messageDatatable.focusTable = this.messageDatatable.datatableOtMessageItem
})
}
openNewMessageModal() {