mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadidas mejoras propuestas por Manolo a la importacion de RAMA
This commit is contained in:
@ -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();
|
||||
@ -248,11 +264,11 @@ class ImportadorCatalogo extends BaseResourceController
|
||||
'entrega_taller' => 1,
|
||||
];
|
||||
|
||||
return $this->response->setJSON([
|
||||
/*return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'message' => 'Libro encontrado y preparado para importar.',
|
||||
'data' => $dataToImport
|
||||
]);
|
||||
]);*/
|
||||
|
||||
|
||||
// Procedemos a intentar guardar el presupuesto
|
||||
@ -287,7 +303,7 @@ class ImportadorCatalogo extends BaseResourceController
|
||||
$response['data']['sk_id'],
|
||||
$precio_compra,
|
||||
$tirada,
|
||||
null,
|
||||
null,
|
||||
true
|
||||
);
|
||||
if ($respuesta_ajuste['warning'] == true) {
|
||||
|
||||
Reference in New Issue
Block a user