Prrrrrrrrrrr

This commit is contained in:
imnavajas
2025-04-15 16:05:11 +02:00
parent 67e588dd67
commit 7cf1bf006d
9 changed files with 748 additions and 32 deletions

View File

@ -8,12 +8,28 @@ use CodeIgniter\Router\RouteCollection;
$routes->group('catalogo', ['namespace' => 'App\Controllers\Catalogo'], function ($routes) {
/* Libros */
$routes->group('libros', ['namespace' => 'App\Controllers\Catalogo'], function ($routes) {
/**======================
* CRUD
*========================**/
$routes->get('', 'CatalogoLibros::index', ['as' => 'CatalogoLibrosList']);
$routes->get('gettarifas', 'CatalogoLibros::getSelect2');
$routes->match(['get', 'post'], 'add', 'CatalogoLibros::add', ['as' => 'CatalogoLibrosAdd']);
$routes->match(['get', 'post'], 'edit/(:num)', 'CatalogoLibros::edit/$1', ['as' => 'CatalogoLibrosEdit']);
$routes->get('delete/(:num)', 'CatalogoLibros::delete/$1', ['as' => 'CatalogoLibrosDelete']);
$routes->get('datatable', 'CatalogoLibros::datatable', ['as' => 'CatalogoLibrosDT']);
$routes->get('select', 'CatalogoLibros::show_select', ["as" => "CatalogoLibrosShow"]);
/**======================
* AJAX
*========================**/
$routes->get('clientlist', 'CatalogoLibros::getClientList', ['as' => 'clientList']);
/**======================
* FILES
*========================**/
$routes->post('get_files', 'CatalogoLibros::get_files');
$routes->post('upload_files', 'CatalogoLibros::upload_files');
});
});

View File

@ -3,8 +3,8 @@ namespace App\Controllers\Catalogo;
use App\Controllers\BaseResourceController;
use App\Entities\Catalogo\CatalogoLibroEntity;
use App\Models\Collection;
use App\Models\Catalogo\CatalogoLibroModel;
use App\Models\Clientes\ClienteModel;
use Hermawan\DataTables\DataTable;
class CatalogoLibros extends BaseResourceController
@ -178,6 +178,10 @@ class CatalogoLibros extends BaseResourceController
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$catalogoLibrosEntity->clienteName = model('App\Models\Clientes\ClienteModel')->find($catalogoLibrosEntity->cliente_id)->nombre;
$catalogoLibrosEntity->createdUser = model('App\Models\Usuarios\UserModel')->getFullName($catalogoLibrosEntity->user_created_id);
$catalogoLibrosEntity->updatedUser = model('App\Models\Usuarios\UserModel')->getFullName($catalogoLibrosEntity->user_update_id);
$this->viewData['catalogoLibrosEntity'] = $catalogoLibrosEntity;
$this->viewData['formAction'] = route_to('CatalogoLibrosEdit', $id);
@ -297,4 +301,102 @@ class CatalogoLibros extends BaseResourceController
}
}
/* IMN */
public function getClientList()
{
$search = $this->request->getGet("q") ?? "";
$data = (new ClienteModel())->getIdName($search);
return $this->response->setJSON($data);
}
public function get_files()
{
// Check if the request is a POST request
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$presupuesto_id = $this->request->getPost()['presupuesto_id'] ?? 0;
$model = model('App\Models\Presupuestos\PresupuestoFicheroModel');
$files = $model->getFiles($presupuesto_id);
$result = [];
foreach ($files as $file) {
$size = filesize($file->file_path);
$splitPath = explode("presupuestos/", $file->file_path);
// se crea un objeto con el nombre del fichero y el tamaño
$obj = (object) array(
'name' => $file->nombre,
'size' => $size,
'hash' => $splitPath[1] ?? $file->file_path
);
// se añade el objeto al array
array_push($result, $obj);
}
return json_encode($result);
}
}
public function upload_files()
{
$model = model('App\Models\Presupuestos\PresupuestoFicheroModel');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$presupuesto_id = $_POST['presupuesto_id'];
$old_files = json_decode($_POST['oldFiles']);
$ftp = new SafekatFtpClient();
// Comprobar si se han subido archivos
if (!empty($_FILES['file']) || !empty($old_files)) {
// Borrar los archivos existentes del presupuesto
$ftp->removeFiles($presupuesto_id);
$model->deleteFiles($presupuesto_id, $old_files);
if (!empty($_FILES['file'])) {
$files = $_FILES['file'];
// Iterar sobre los archivos
for ($i = 0; $i < count($files['name']); $i++) {
// Aquí puedes acceder a las propiedades del archivo
$name = $files['name'][$i];
$extension = explode('.', $files['name'][$i])[1];
$tmp_name = $files['tmp_name'][$i];
$new_name = $model->saveFileInBBDD($presupuesto_id, $name, $extension, auth()->id());
// Se sube el fichero
// Pero primero se comprueba que la carpeta presupuestos exista
if (!is_dir(WRITEPATH . 'uploads/presupuestos')) {
mkdir(WRITEPATH . 'uploads/presupuestos', 0777, true);
}
if (!is_null($new_name)) {
$path = WRITEPATH . 'uploads/presupuestos/' . $new_name;
move_uploaded_file($tmp_name, $path);
}
}
$ftp->uploadFilePresupuesto($presupuesto_id);
}
} else {
// Borrar los archivos existentes del presupuesto
$ftp->removeFiles($presupuesto_id);
$model->deleteFiles($presupuesto_id);
}
}
return json_encode(['message' => 'Archivos subidos correctamente']);
}
}

View File

@ -56,10 +56,33 @@ class Intranet extends Controller
}
}
function orden_trabajo($ot_id,$resource_name)
function orden_trabajo($ot_id, $resource_name)
{
helper('file');
$resource_path = WRITEPATH . 'uploads/orden_trabajo/'.$ot_id. '/' . $resource_name;
$resource_path = WRITEPATH . 'uploads/orden_trabajo/' . $ot_id . '/' . $resource_name;
if (file_exists($resource_path)) {
// Get the mime type of the file
$mime_type = mime_content_type($resource_path);
// Get an instance of the Response class
$response = service('response');
// Set the content type
$response->setContentType($mime_type);
// Set the output
$response->setBody(file_get_contents($resource_path));
// Send the response to the browser
$response->send();
}
}
function catalogo($catalogo_id, $resource_name)
{
helper('file');
$resource_path = WRITEPATH . 'uploads/catalogo/' . $catalogo_id . '/' . $resource_name;
if (file_exists($resource_path)) {
// Get the mime type of the file
$mime_type = mime_content_type($resource_path);

View File

@ -4,15 +4,16 @@ namespace App\Models\Catalogo;
use CodeIgniter\Model;
use App\Entities\Catalogo\CatalogoLibroEntity;
use App\Models\Clientes\ClienteModel;
class CatalogoLibroModel extends Model
{
protected $table = 'catalogo_libros';
protected $primaryKey = 'id';
protected $table = 'catalogo_libros';
protected $primaryKey = 'id';
protected $returnType = CatalogoLibroEntity::class;
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $returnType = CatalogoLibroEntity::class;
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $allowedFields = [
'cliente_id',
@ -68,16 +69,16 @@ class CatalogoLibroModel extends Model
];
protected $useAutoIncrement = true;
protected $protectFields = true;
protected $protectFields = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Opcional: reglas de validación
protected $validationRules = [];
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $skipValidation = false;
@ -107,4 +108,19 @@ class CatalogoLibroModel extends Model
return $builder;
}
public function getClientList($search = "")
{
$clienteModel = new ClienteModel();
$query = $clienteModel->builder()
->select('id, nombre as name') // O el campo que quieras usar como "name"
->where('deleted_at', null);
if ($search != "") {
$query->groupStart()
->orLike("nombre", $search)
->groupEnd();
}
return $query->get()->getResultObject();
}
}

View File

@ -32,8 +32,12 @@
<div class="col-md-12 col-lg-10 px-4">
<div class="row">
<div class="col-md-4 mb-3">
<label for="cliente_id" class="form-label">Cliente</label>
<select id="cliente_id" name="cliente_id" class="form-select select2bs5"></select>
<label for="clienteId" class="form-label">Cliente</label>
<select id="clienteId" name="clienteId" class="form-select select2bs5">
<option value="<?= $catalogoLibrosEntity->cliente_id ?>">
<?= $catalogoLibrosEntity->clienteName ?>
</option>
</select>
</div>
<div class="col-md-8 mb-3">
@ -81,8 +85,8 @@
<div class="col-md-6 mb-3">
<label for="ean" class="form-label">EAN</label>
<input type="text" id="ean" name="ean" class="form-control" readonly style="background: #E8E8E8;"
value="<?= old('ean', $catalogoLibrosEntity->ean) ?>">
<input type="text" id="ean" name="ean" class="form-control" readonly
style="background: #E8E8E8;" value="<?= old('ean', $catalogoLibrosEntity->ean) ?>">
</div>
<div class="col-md-3 mb-3">

View File

@ -12,19 +12,34 @@
<div class="row">
<!-- Zona de subida -->
<div class="col-md-12 col-lg-3 px-4">
<div id="dropzone" class="border border-secondary border-dashed rounded p-4 text-center"
style="min-height: 200px; cursor: pointer;">
<p class="text-muted m-0">
Arrastre los ficheros<br>o haz click para<br><strong>subir ficheros</strong>
</p>
<!-- Aquí podrías usar DropzoneJS u otro uploader -->
<input type="file" multiple name="archivos[]" class="d-none" id="fileUploader">
<div class="col-12 mb-3">
<h3>Ficheros</h3>
<div class="col-12">
<div class="dropzone needsclick" id="dropzone-multi">
<div class="dz-message needsclick">
Arrastre aquí los ficheros o haga click
</div>
<div class="fallback">
<input name="file" type="file" />
</div>
</div>
</div>
<button id="btnUploadFile"
class="btn mt-3 btn-primary btn-submit waves-effect waves-light ml-2 ">
<span
class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('App.global_upload_files') ?></span>
<i class="ti ti-upload ti-xs"></i>
</button>
<button id="submit-all-files"
class="btn mt-3 btn-success btn-submit waves-effect waves-light ml-2">
<span
class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('App.global_save_file') ?></span>
<i class="ti ti-device-floppy ti-xs"></i>
</button>
</div>
<!-- Tabla de ficheros -->
<div class="col-md-12 col-lg-9 px-4">
<div class="col-md-12 col-lg-12 px-4">
<div class="table-responsive">
<table class="table table-bordered">
<thead class="table-light">

View File

@ -4,15 +4,15 @@
<div class="col-md-6">
<p>
<strong><?= lang("Catalogo.created_by_at") ?></strong>
<span id="created_by"></span>,
<span id="created_at"></span>
<span id="created_by"><?= $catalogoLibrosEntity->createdUser ?></span>,
<span id="created_at"><?= $catalogoLibrosEntity->created_at ?></span>
</p>
</div>
<div class="col-md-6">
<p>
<strong><?= lang("Catalogo.updated_by_at") ?></strong>
<span id="updated_by"></span>,
<span id="updated_at_footer"></span>
<span id="updated_by"><?= $catalogoLibrosEntity->updatedUser ?></span>,
<span id="updated_at_footer"><?= $catalogoLibrosEntity->updated_at ?></span>
</p>
</div>
</div>

View File

@ -36,4 +36,16 @@
</div><!-- //.card -->
</div><!--//.col -->
</div><!--//.row -->
<?= $this->endSection() ?>
<?= $this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/dropzone/dropzone.css') ?>" />
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/safekat.css') ?>">
<?= $this->endSection() ?>
<?= $this->section("additionalExternalJs") ?>
<script src="<?= site_url("themes/vuexy/vendor/libs/dropzone/dropzone.js") ?>"></script>
<script type="module" src="<?= site_url('assets/js/safekat/pages/catalogo/catalogo.js?' . 'token' . '=' . (csrf_token() ?? "token")) ?>"></script>
<?= $this->endSection() ?>