Merge branch 'fix/varios' into 'main'

Fix/varios

See merge request jjimenez/safekat!784
This commit is contained in:
Ignacio Martinez Navajas
2025-05-05 18:14:05 +00:00
6 changed files with 86 additions and 33 deletions

View File

@ -3,6 +3,7 @@ namespace App\Controllers\Importadores;
use App\Controllers\BaseResourceController;
use App\Entities\Catalogo\CatalogoLibroEntity;
use App\Models\Presupuestos\PresupuestoModel;
use App\Models\Catalogo\CatalogoLibroModel;
use App\Controllers\Presupuestos\Presupuestocliente;
use App\Services\PresupuestoService;
@ -45,7 +46,7 @@ class ImportadorCatalogo extends BaseResourceController
$viewData = [
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Importador.importadorCatalogoTitle')]),
];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
@ -58,37 +59,51 @@ class ImportadorCatalogo extends BaseResourceController
{
$json = $this->request->getJSON();
if (!$json || !isset($json->fila[0])) {
// Validación inicial del JSON y del ISBN
if (!$json || !isset($json->fila[0]) || empty(trim($json->fila[0]))) {
return $this->response->setJSON([
'apto' => false,
'reason' => 'Datos inválidos'
'reason' => 'ISBN no proporcionado o datos inválidos'
]);
}
$input = trim($json->fila[0]); // Asumimos que 'input' es el primer campo de la fila
$input = trim($json->fila[0]); // ISBN
$refCliente = isset($json->fila[1]) ? trim($json->fila[1]) : null;
if (empty($input)) {
// Validar formato del refCliente (esperado: idpedido-idlinea)
if (empty($refCliente) || strpos($refCliente, '-') === false) {
return $this->response->setJSON([
'apto' => false,
'reason' => 'ISBN no proporiconado'
'reason' => 'Ref. cliente inválido'
]);
}
// 1. Comprobar duplicado en tabla de presupuestos
$presupuestoModel = new PresupuestoModel(); // Usa el modelo real que corresponda
$yaExiste = $presupuestoModel->where('referencia_cliente', $refCliente)->first();
if ($yaExiste) {
return $this->response->setJSON([
'apto' => false,
'reason' => 'Referencia ya importada'
]);
}
$catalogoModel = new CatalogoLibroModel();
// 1. Buscar por ISBN exacto
// 2. Buscar por ISBN exacto
$libroPorIsbn = $catalogoModel->where('isbn', $input)->first();
if ($libroPorIsbn) {
return $this->response->setJSON([
'apto' => true
]);
}
// 2. Buscar por EAN sin guiones
// 3. Buscar por EAN sin guiones
$eanLimpio = str_replace('-', '', $input);
$libroPorEan = $catalogoModel->where('REPLACE(ean, "-", "")', $eanLimpio)->first();
$libroPorEan = $catalogoModel
->where('REPLACE(ean, "-", "")', $eanLimpio, false) // false para evitar escapado automático
->first();
if ($libroPorEan) {
return $this->response->setJSON([
@ -96,7 +111,7 @@ class ImportadorCatalogo extends BaseResourceController
]);
}
// No encontrado
// 4. No encontrado
return $this->response->setJSON([
'apto' => false,
'reason' => 'No encontrado en catálogo'
@ -105,6 +120,7 @@ class ImportadorCatalogo extends BaseResourceController
public function importarFila()
{
$json = $this->request->getJSON();
@ -287,7 +303,7 @@ class ImportadorCatalogo extends BaseResourceController
$response['data']['sk_id'],
$precio_compra,
$tirada,
null,
null,
true
);
if ($respuesta_ajuste['warning'] == true) {

View File

@ -10,6 +10,7 @@ use App\Models\Tarifas\Acabados\ServicioAcabadoModel;
use App\Models\Clientes\ClienteModel;
class CatalogoLibroEntity extends Entity
{
protected $attributes = [
'id' => null,
'cliente_id' => null,
@ -44,8 +45,6 @@ class CatalogoLibroEntity extends Entity
'sello' => null,
'paginas' => 0,
'tipo_impresion' => null,
'solapas_ancho' => 0.00,
'cubiertas_ancho' => 0.00,
'comentarios' => '',
'negro_paginas' => null,
'negro_papel' => null,
@ -63,6 +62,8 @@ class CatalogoLibroEntity extends Entity
'cubierta_papel' => null,
'cubierta_papel_id' => null,
'cubierta_gramaje' => null,
'cubierta_ancho_solapas' => 0.00,
'cubierta_acabado_id' => null,
'cubierta_acabado' => null,
'cubierta_pod_papel_id' => null,
'cubierta_pod_gramaje' => null,
@ -70,10 +71,12 @@ class CatalogoLibroEntity extends Entity
'sobrecubierta_papel' => null,
'sobrecubierta_papel_id' => null,
'sobrecubierta_gramaje' => null,
'sobrecubierta_acabado_id' => null,
'sobrecubierta_acabado' => null,
'sobrecubierta_pod_papel_id' => null,
'sobrecubierta_ancho_solapas' => 0.00,
'sobrecubierta_pod_gramaje' => null,
'encuardenacion_id' => 'null',
'encuadernacion_id' => null,
'ubicacion' => null,
'created_at' => null,
'updated_at' => null,
@ -97,8 +100,6 @@ class CatalogoLibroEntity extends Entity
'num_ilustr_color' => '?int',
'num_ilustr_bn' => '?int',
'paginas' => 'int',
'solapas_ancho' => 'float',
'cubiertas_ancho' => 'float',
'negro_paginas' => '?int',
'negro_gramaje' => '?float',
'negro_papel_id' => '?int',
@ -113,15 +114,19 @@ class CatalogoLibroEntity extends Entity
'cubierta_gramaje' => '?float',
'cubierta_papel_id' => '?int',
'cubierta_pod_papel_id' => '?int',
'cubierta_ancho_solapas' => 'float',
'cubierta_pod_gramaje' => '?float',
'cubierta_acabado_id' => '?int',
'sobrecubierta_paginas' => '?int',
'sobrecubierta_gramaje' => '?float',
'sobrecubierta_papel_id' => '?int',
'sobrecubierta_pod_papel_id' => '?int',
'sobrecubierta_ancho_solapas' => 'float',
'sobrecubierta_pod_gramaje' => '?float',
'sobrecubierta_acabado_id' => '?int',
'encuadernacion_id' => '?int',
'fecha_disponibilidad' => 'datetime',
'fecha_public' => 'datetime',
];
public function getClienteName()

View File

@ -721,7 +721,7 @@ return [
"menu_digitalizacion" => "Digitalización",
"menu_importadores" => "Importadores",
"menu_importadores_catalogo" => "Desde catálogo",
"menu_importadores_catalogo" => "RA-MA", //"Desde catálogo",
"menu_importadores_bubok" => "Bubok",
"menu_catalogo" => "Catálogo",

View File

@ -25,11 +25,13 @@ if (auth()->user()->can('catalogo.menu')) {
</a>
</li>
<?php } ?>
<li class="menu-item">
<a href="<?= site_url("catalogo/catalogo/importar") ?>" class="menu-link beta">
<?= lang("App.menu_catalogo_importar") ?>
</a>
</li>
<?php if (auth()->user()->inGroup('beta')) { ?>
<li class="menu-item">
<a href="<?= site_url("catalogo/catalogo/importar") ?>" class="menu-link beta">
<?= lang("App.menu_catalogo_importar") ?>
</a>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>