Avance en usuarios de clientes

This commit is contained in:
imnavajas
2024-04-21 21:26:41 +02:00
parent e3182c77dc
commit 9330b3a141
6 changed files with 268 additions and 5 deletions

View File

@ -391,6 +391,10 @@ $routes->group('clienteplantillaprecioslineas', ['namespace' => 'App\Controllers
});
$routes->resource('clienteplantillaprecioslineas', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'clienteplantillaprecioslineas', 'except' => 'show,new,create,update']);
$routes->group('clienteusuarios', ['namespace' => 'App\Controllers\Clientes'], function ($routes) {
$routes->post('datatable', 'Clienteusuarios::datatable', ['as' => 'dataTableOfClienteUsuarios']);
});
$routes->group('formas-pagos', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) {
$routes->get('', 'Formaspagos::index', ['as' => 'formaDePagoList']);

View File

@ -0,0 +1,77 @@
<?php namespace App\Controllers\Clientes;
use App\Controllers\GoBaseResourceController;
use App\Models\Clientes\ClienteUsuariosModel;
use App\Models\Collection;
use App\Entities\Clientes\ClienteContactoEntity;
use App\Models\Clientes\ClienteModel;
use App\Models\Clientes\ClienteContactoModel;
use DataTables\Editor;
use DataTables\Editor\Field;
use DataTables\Editor\Validate;
class Clienteusuarios extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ClienteUsuariosModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Contacto de cliente';
protected static $singularObjectNameCc = 'contactoDeCliente';
protected static $pluralObjectName = 'Contactos de cliente';
protected static $pluralObjectNameCc = 'contactosDeCliente';
protected static $controllerSlug = 'cliente-contactos';
protected static $viewPath = 'themes/backend/vuexy/form/clientes/usuarios/';
protected $indexRoute = 'contactoDeClienteList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('ClienteContactos.moduleTitle');
$this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function datatable()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
$length = $reqData['length'] ?? 5;
$search = $reqData['search']['value'];
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
$order = ClienteUsuariosModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_C = $reqData['id_cliente'] ?? -1;
$resourceData = $this->model->getResource("", $id_C)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource("", $id_C)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -130,8 +130,8 @@ return [
"profile_subtitle_tfa" => "Autenticación de dos factores (2FA)",
"profile_first_name" => "Nombre",
"profile_first_name_ph" => "Escriba su nombre",
"profile_last_name" => "Apellido",
"profile_last_name_ph" => "Escriba su apellido",
"profile_last_name" => "Apellidos",
"profile_last_name_ph" => "Escriba sus apellidos",
"profile_email" => "Correo Electrónico",
"profile_email_ph" => "Escriba su correo electrónico",
"profile_mobile" => "Teléfono Móvil",

View File

@ -0,0 +1,110 @@
<?php
namespace App\Models\Clientes;
class ClienteUsuariosModel extends \App\Models\GoBaseModel
{
protected $table = "auth_user";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.first_name",
1 => "t1.last_name",
2 => "t1.email",
];
protected $allowedFields = ["id", "first_name", "last_name", "email"];
protected $returnType = "App\Entities\Usuarios\UserEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "nombre";
protected $validationRules = [
"last_name" => [
"label" => "ClienteContactos.apellidos",
"rules" => "trim|max_length[500]",
],
"email" => [
"label" => "ClienteContactos.email",
"rules" => "trim|max_length[150]|valid_email|permit_empty",
],
"first_name" => [
"label" => "ClienteContactos.nombre",
"rules" => "trim|max_length[100]",
],
];
protected $validationMessages = [
"last_name" => [
"max_length" => "ClienteContactos.validation.apellidos.max_length",
],
"email" => [
"max_length" => "ClienteContactos.validation.email.max_length",
"valid_email" => "ClienteContactos.validation.email.valid_email",
],
"first_name" => [
"max_length" => "ClienteContactos.validation.nombre.max_length",
],
];
public function findAllWithClientes(string $selcols = "*", int $limit = null, int $offset = 0)
{
$sql =
"SELECT t1." .
$selcols .
", t2.nombre AS cliente_id FROM " .
$this->table .
" t1 LEFT JOIN clientes t2 ON t1.cliente_id = t2.id";
if (!is_null($limit) && intval($limit) > 0) {
$sql .= " LIMIT " . $limit;
}
if (!is_null($offset) && intval($offset) > 0) {
$sql .= " OFFSET " . $offset;
}
$query = $this->db->query($sql);
$result = $query->getResultObject();
return $result;
}
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $cliente_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id_user AS id, t1.first_name AS nombre, t1.last_name AS apellidos, t1.email AS email"
);
$builder->where('t1.id_user', $cliente_id);
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.first_name", $search)
->orLike("t1.last_name", $search)
->orLike("t1.email", $search)
->groupEnd();
}
}

View File

@ -659,7 +659,20 @@
</div>
<div class="tab-pane fade" id="usuarios" role="tabpanel">
<h3>Proximanente</h3>
<table id="tableOfClienteUsuarios" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th>ID</th>
<th><?= lang('App.profile_first_name') ?></th>
<th><?= lang('App.profile_last_name') ?></th>
<th><?= lang('App.profile_email') ?></th>
<th class="text-nowrap" style="min-width:100px"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<?php } ?>
@ -1435,6 +1448,67 @@ function delete_direccion_envio(dataId){
<?=$this->endSection() ?>
<?= $this->section("additionalInlineJs") ?>
/****************************************
Contactos
*****************************************/
const lastColNrCU = $('#tableOfClienteUsuarios').find("tr:first th").length - 1;
var theTableCU = $('#tableOfClienteUsuarios').DataTable( {
serverSide: true,
processing: true,
autoWidth: true,
responsive: true,
lengthMenu: [ 5, 10, 25],
order: [[ 0, "asc" ], [ 1, "asc" ]],
pageLength: 10,
lengthChange: true,
searching: false,
paging: true,
info: false,
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfClienteUsuarios') ?>',
data: {
//id_cliente: id,
id_cliente: 1,
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns: [
{ 'data': 'id' },
{ 'data': 'nombre' },
{ 'data': 'apellidos' },
{ 'data': 'email' },
{
data: actionBtns,
className: 'row-edit dt-center'
}
],
columnDefs: [
{
orderable: false,
searchable: false,
targets: [lastColNrCU]
},
{
"orderData": [ 0, 1 ],
"targets": 0
},
],
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
}
} );
<?=$this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.bootstrap5.min.css') ?>">

View File

@ -230,11 +230,9 @@
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.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/css/sk-datatables.css') ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/safekat.css') ?>">
<?=$this->endSection() ?>