Trabajando JS

This commit is contained in:
unknown
2025-04-27 22:00:52 +02:00
parent 6f8890a8b1
commit 6d45a950df
5 changed files with 233 additions and 109 deletions

View File

@ -9,7 +9,7 @@ $routes->group('importador', ['namespace' => 'App\Controllers\Importadores'], fu
/* Libros */
$routes->group('catalogo', ['namespace' => 'App\Controllers\Importadores'], function ($routes) {
/**======================
* CRUD
* Tool
*========================**/
$routes->get('', 'ImportadorCatalogo::index', ['as' => 'importadorCatalogoTool']);
@ -17,6 +17,7 @@ $routes->group('importador', ['namespace' => 'App\Controllers\Importadores'], fu
/**======================
* AJAX
*========================**/
$routes->post('validar-fila', 'ImportadorCatalogo::validarFila');
});

View File

@ -185,4 +185,53 @@ class ImportadorCatalogo extends BaseResourceController
public function validarFila()
{
$json = $this->request->getJSON();
if (!$json || !isset($json->fila[0])) {
return $this->response->setJSON([
'apto' => false,
'reason' => 'Datos inválidos'
]);
}
$input = trim($json->fila[0]); // Asumimos que 'input' es el primer campo de la fila
if (empty($input)) {
return $this->response->setJSON([
'apto' => false,
'reason' => 'ISBN no proporiconado'
]);
}
$catalogoModel = new CatalogoLibroModel();
// 1. Buscar por ISBN exacto
$libroPorIsbn = $catalogoModel->where('isbn', $input)->first();
if ($libroPorIsbn) {
return $this->response->setJSON([
'apto' => true
]);
}
// 2. Buscar por EAN sin guiones
$eanLimpio = str_replace('-', '', $input);
$libroPorEan = $catalogoModel->where('REPLACE(ean, "-", "")', $eanLimpio)->first();
if ($libroPorEan) {
return $this->response->setJSON([
'apto' => true
]);
}
// No encontrado
return $this->response->setJSON([
'apto' => false,
'reason' => 'No encontrado en catálogo'
]);
}
}

View File

@ -9,6 +9,8 @@ return [
'idlinea' => 'Ref. cliente',
'cnt_pedida' => 'Unidades',
'precio_compra' => 'Precio Compra',
'importar' => 'Importar',
'subirArchivo' => 'Cargar Excel proporcionado por RA-MA',
'libro' => 'libro',
'id' => 'ID',

View File

@ -10,47 +10,79 @@
<div class="card-header">
<h3 class="card-title"><?= lang('Importador.importadorCatalogoTitle') ?></h3>
</div><!--//.card-header -->
<div class="card-body">
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<input type="file" id="excelFile" accept=".xlsx, .xls">
<div id="tableContainer"></div>
<form id="catalogoLibroForm" class="card-body" method="post" action="#">
<?= csrf_field() ?>
<br>
<button id="importBtn">Importar</button>
<!-- card-body -->
<div class="card-body">
<table id="excelTable" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Importador.input') ?></th>
<th><?= lang('Importador.idlinea') ?></th>
<th><?= lang('Importador.descripcion') ?></th>
<th><?= lang('Importador.cnt_pedida') ?></th>
<th><?= lang('Importador.precio_compra') ?></th>
<th class="text-nowrap" style="min-width: 85px;"><?= lang('Basic.global.Action') ?></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<div class="row">
</tbody>
</table>
<div class="col-md-6 mb-3">
<label for="excelFile"
class="form-label"><?= lang('Importador.subirArchivo') ?? 'Subir archivo Excel' ?></label>
<input type="file" class="form-control" id="excelFile" name="excelFile"
accept=".xlsx, .xls">
</div>
<div class="col-md-4 mb-3 d-flex align-items-end">
<button type="button" id="importBtn" class="btn btn-success w-100">
<i class="fas fa-file-import me-2"></i> <?= lang('Importador.importar') ?? 'Importar' ?>
</button>
</div>
<div class="col-md-12 mb-3">
</div><!--//.card-body -->
<div class="card-footer">
<div class="table-responsive">
<table id="excelTable" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th>
<input type="checkbox" id="select-all" class="form-check-input">
</th>
<th><?= lang('Importador.input') ?></th>
<th><?= lang('Importador.idlinea') ?></th>
<th><?= lang('Importador.descripcion') ?></th>
<th><?= lang('Importador.cnt_pedida') ?></th>
<th><?= lang('Importador.precio_compra') ?></th>
<th class="text-nowrap" style="min-width: 120px;">
<?= lang('Basic.global.Action') ?></th>
</tr>
<tr>
<th></th>
<th><input type="text" class="form-control form-control-sm"
placeholder="Filtrar..." /></th>
<th><input type="text" class="form-control form-control-sm"
placeholder="Filtrar..." /></th>
<th><input type="text" class="form-control form-control-sm"
placeholder="Filtrar..." /></th>
<th><input type="text" class="form-control form-control-sm"
placeholder="Filtrar..." /></th>
<th><input type="text" class="form-control form-control-sm"
placeholder="Filtrar..." /></th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div><!--//.card-footer -->
</div><!--//.card -->
</div><!--//.col -->
</div>
</div>
</div>
</form>
</div><!--//.card-body -->
<div class="card-footer">
</div><!--//.card-footer -->
</div><!--//.card -->
</div><!--//.col -->
</div><!--//.row -->
<?= $this->endSection() ?>