mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Primera version del importador de Bubok
This commit is contained in:
@ -6,20 +6,33 @@ use CodeIgniter\Router\RouteCollection;
|
|||||||
|
|
||||||
/* Rutas para tarifas */
|
/* Rutas para tarifas */
|
||||||
$routes->group('importador', ['namespace' => 'App\Controllers\Importadores'], function ($routes) {
|
$routes->group('importador', ['namespace' => 'App\Controllers\Importadores'], function ($routes) {
|
||||||
/* Libros */
|
|
||||||
|
/* Desde Catalogo */
|
||||||
$routes->group('catalogo', ['namespace' => 'App\Controllers\Importadores'], function ($routes) {
|
$routes->group('catalogo', ['namespace' => 'App\Controllers\Importadores'], function ($routes) {
|
||||||
/**======================
|
/**======================
|
||||||
* Tool
|
* Tool
|
||||||
*========================**/
|
*========================**/
|
||||||
$routes->get('', 'ImportadorCatalogo::index', ['as' => 'importadorCatalogoTool']);
|
$routes->get('', 'ImportadorCatalogo::index', ['as' => 'importadorCatalogoTool']);
|
||||||
|
|
||||||
|
|
||||||
/**======================
|
/**======================
|
||||||
* AJAX
|
* AJAX
|
||||||
*========================**/
|
*========================**/
|
||||||
$routes->post('validar-fila', 'ImportadorCatalogo::validarFila');
|
$routes->post('validar-fila', 'ImportadorCatalogo::validarFila');
|
||||||
$routes->post('importar-fila', 'ImportadorCatalogo::importarFila');
|
$routes->post('importar-fila', 'ImportadorCatalogo::importarFila');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Desde Cliente Bubok */
|
||||||
|
$routes->group('bubok', ['namespace' => 'App\Controllers\Importadores'], function ($routes) {
|
||||||
|
/**======================
|
||||||
|
* Tool
|
||||||
|
*========================**/
|
||||||
|
$routes->get('', 'ImportadorBubok::index', ['as' => 'importadorBubokTool']);
|
||||||
|
|
||||||
|
/**======================
|
||||||
|
* AJAX
|
||||||
|
*========================**/
|
||||||
|
$routes->post('importar-fila', 'ImportadorBubok::importarFila');
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
363
ci4/app/Controllers/Importadores/ImportadorBubok.php
Normal file
363
ci4/app/Controllers/Importadores/ImportadorBubok.php
Normal file
@ -0,0 +1,363 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Controllers\Importadores;
|
||||||
|
|
||||||
|
use App\Controllers\BaseResourceController;
|
||||||
|
use App\Controllers\Presupuestos\Presupuestocliente;
|
||||||
|
use App\Services\PresupuestoService;
|
||||||
|
|
||||||
|
class ImportadorBubok extends BaseResourceController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $format = 'json';
|
||||||
|
|
||||||
|
protected static $singularObjectName = 'Importador';
|
||||||
|
protected static $singularObjectNameCc = 'ImportadorBubok';
|
||||||
|
protected static $pluralObjectName = 'Importadores';
|
||||||
|
protected static $pluralObjectNameCc = 'importadores';
|
||||||
|
|
||||||
|
protected static $controllerSlug = 'importador';
|
||||||
|
|
||||||
|
protected static $viewPath = 'themes/vuexy/form/importador/bubok/';
|
||||||
|
|
||||||
|
protected $indexRoute = 'ImportadorBubokTool';
|
||||||
|
|
||||||
|
|
||||||
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
$this->viewData['pageTitle'] = lang('Importador.listingPage');
|
||||||
|
$this->viewData['usingSweetAlert'] = true;
|
||||||
|
|
||||||
|
// Breadcrumbs (IMN)
|
||||||
|
$this->viewData['breadcrumb'] = [
|
||||||
|
['title' => lang("App.menu_importadores"), 'route' => "javascript:void(0);", 'active' => false],
|
||||||
|
['title' => lang("App.menu_importadores_bubok"), 'route' => route_to('importadorBubokTool'), 'active' => true]
|
||||||
|
];
|
||||||
|
|
||||||
|
parent::initController($request, $response, $logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
|
||||||
|
$viewData = [
|
||||||
|
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Importador.importadorCatalogoTitle')]),
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||||
|
|
||||||
|
return view(static::$viewPath . 'viewImportadorBubokTool', $viewData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function importarFila()
|
||||||
|
{
|
||||||
|
$json = $this->request->getJSON();
|
||||||
|
|
||||||
|
// Validación mínima de datos comunes
|
||||||
|
$pedido = $json->pedido ?? null;
|
||||||
|
if (!$pedido || !isset($pedido->orderNumber)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Datos comunes del pedido ausentes o inválidos.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación mínima de existencia del producto en la linea
|
||||||
|
if (!$json || !isset($json->producto)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Producto no proporcionado o inválido.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$producto = $json->producto;
|
||||||
|
|
||||||
|
// 1. Datos básicos:
|
||||||
|
// Referencia del cliente
|
||||||
|
$orderNumber = $pedido->orderNumber ?? null;
|
||||||
|
$productId = $producto->id ?? null;
|
||||||
|
if (is_null($orderNumber) || is_null($productId)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Número de orden o ID del producto no reconocidos.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$refCliente = "$orderNumber - $productId";
|
||||||
|
|
||||||
|
// Titulo
|
||||||
|
$titulo = $producto->title ?? null;
|
||||||
|
if (is_null($titulo)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Título del libro no reconocido.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación de páginas y tirada
|
||||||
|
$paginas = isset($producto->body->pages) ? (int) $producto->body->pages : 0;
|
||||||
|
$tirada = isset($producto->amount) ? (int) $producto->amount : 0;
|
||||||
|
if ($paginas <= 0 || $tirada <= 0) {
|
||||||
|
$errores = [];
|
||||||
|
if ($paginas <= 0) {
|
||||||
|
$errores[] = 'Número de páginas inválido.';
|
||||||
|
}
|
||||||
|
if ($tirada <= 0) {
|
||||||
|
$errores[] = 'Tirada inválida.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => implode(' ', $errores)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ancho y alto
|
||||||
|
$ancho = null;
|
||||||
|
$alto = null;
|
||||||
|
foreach ($producto->size as $key => $val) {
|
||||||
|
if ($val == 1) {
|
||||||
|
// ejemplo: size170x235
|
||||||
|
$size = str_replace('size', '', $key);
|
||||||
|
[$ancho, $alto] = explode('x', $size);
|
||||||
|
$ancho = (int) $ancho;
|
||||||
|
$alto = (int) $alto;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$ancho || !$alto) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Tamaño del libro no reconocido.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*$numGuardaPages = 4;
|
||||||
|
$hasGuarda = !empty($producto->cover->guarda);
|
||||||
|
if ($hasGuarda)
|
||||||
|
$paginas += $numGuardaPages;*/
|
||||||
|
|
||||||
|
// 2. Interior: color o negro
|
||||||
|
// Determinar tipo de impresión interior
|
||||||
|
$interiorTipo = null;
|
||||||
|
if (isset($producto->body->color->CMYK) && $producto->body->color->CMYK == '1') {
|
||||||
|
$interiorTipo = 'color';
|
||||||
|
} elseif (isset($producto->body->color->Monochrome) && $producto->body->color->Monochrome == '1') {
|
||||||
|
$interiorTipo = 'negro';
|
||||||
|
} elseif (isset($producto->body->color->Semicolor) && $producto->body->color->Semicolor == '1') {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Tipo de impresión "Semicolor" no soportado.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($interiorTipo)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'No se pudo determinar si el interior es en color o blanco y negro.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determinar tipo de papel interior
|
||||||
|
$papelInteriorId = null;
|
||||||
|
if (isset($producto->body->paperColor->white) && $producto->body->paperColor->white == '1') {
|
||||||
|
$papelInteriorId = 3; // Offset blanco 'OFF1'
|
||||||
|
} elseif (isset($producto->body->paperColor->cream) && $producto->body->paperColor->cream == '1') {
|
||||||
|
$papelInteriorId = 4; // Offset ahuesado 'OFF2'
|
||||||
|
} else {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Tipo de papel interior no definido.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determinar el gramaje del papel
|
||||||
|
$gramajePapelInterior = null;
|
||||||
|
foreach ($producto->body->paperWeight as $key => $val) {
|
||||||
|
if ($val == 1) {
|
||||||
|
$gramajePapelInterior = (int) str_replace(['weight', 'gr'], '', $key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$gramajePapelInterior) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Gramaje del papel no válido.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Encuadernación
|
||||||
|
// Tapa dura
|
||||||
|
$tapaDura = isset($producto->cover->type->tapadura) && $producto->cover->type->tapadura == '1';
|
||||||
|
|
||||||
|
// Solapas
|
||||||
|
$solapas = isset($producto->cover->type->consolapas) && $producto->cover->type->consolapas == '1';
|
||||||
|
|
||||||
|
// Doble cara (a veces se activa con tapa dura) una cara => 2; dos caras => 4
|
||||||
|
$doscara = false;
|
||||||
|
|
||||||
|
// Tipo de encuadernado
|
||||||
|
$encuadernadoId = null;
|
||||||
|
|
||||||
|
if (isset($producto->cover->coverType->SoftCover) && $producto->cover->coverType->SoftCover == '1') {
|
||||||
|
if ($tapaDura) {
|
||||||
|
$encuadernadoId = 1; // Libro fresado tapa dura
|
||||||
|
$doscara = true;
|
||||||
|
} else {
|
||||||
|
$encuadernadoId = 2; // Libro fresado tapa blanda
|
||||||
|
}
|
||||||
|
} elseif (isset($producto->cover->coverType->SaddleStitch) && $producto->cover->coverType->SaddleStitch == '1') {
|
||||||
|
if ($tapaDura) {
|
||||||
|
$encuadernadoId = 3; // Libro cosido tapa dura
|
||||||
|
$doscara = true;
|
||||||
|
} else {
|
||||||
|
$encuadernadoId = $solapas ? 20 : 4; // Libro cosido tapa blanda (solapas) : (sin solapas)
|
||||||
|
}
|
||||||
|
} elseif (isset($producto->cover->coverType->CoilBinding) && $producto->cover->coverType->CoilBinding == '1') {
|
||||||
|
if ($tapaDura) {
|
||||||
|
$encuadernadoId = 5; // Libro espiral tapa dura
|
||||||
|
$doscara = true;
|
||||||
|
} else {
|
||||||
|
$encuadernadoId = 6; // Libro espiral tapa blanda
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$encuadernadoId) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Tipo de encuadernación no identificado.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determinar el acabado de la cubierta
|
||||||
|
$acabadoId = null;
|
||||||
|
if (isset($producto->cover->acabado->brillo) && $producto->cover->acabado->brillo == '1') {
|
||||||
|
$acabadoId = 1; // Plastificado brillo 1/c
|
||||||
|
} elseif (isset($producto->cover->acabado->mate) && $producto->cover->acabado->mate == '1') {
|
||||||
|
$acabadoId = 2; // Plastificado mate 1/c
|
||||||
|
} else {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'Tipo de acabado de cubierta no definido.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. ENVÍO: recuperamos la primera dirección del cliente BUBOK (ID 40)
|
||||||
|
$clienteDireccionModel = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||||
|
$direccionCliente = $clienteDireccionModel
|
||||||
|
->where('cliente_id', 40)
|
||||||
|
->orderBy('id', 'asc')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$direccionCliente) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => 'El cliente Bubok no tiene direcciones asociadas.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$direcciones = [
|
||||||
|
[
|
||||||
|
'direccion' => [
|
||||||
|
'id' => (int) $direccionCliente->id,
|
||||||
|
'cliente_id' => (int) $direccionCliente->cliente_id,
|
||||||
|
'cliente_nombre' => $direccionCliente->clienteNombre,
|
||||||
|
'att' => $direccionCliente->persona_contacto ?? '',
|
||||||
|
'alias' => $direccionCliente->alias ?? '',
|
||||||
|
'email' => $direccionCliente->email ?? '',
|
||||||
|
'direccion' => $direccionCliente->direccion,
|
||||||
|
'pais_id' => (int) $direccionCliente->pais_id,
|
||||||
|
'pais' => $direccionCliente->paisNombre,
|
||||||
|
'municipio' => $direccionCliente->municipio,
|
||||||
|
'provincia' => $direccionCliente->provincia,
|
||||||
|
'cp' => $direccionCliente->cp,
|
||||||
|
'telefono' => $direccionCliente->telefono,
|
||||||
|
],
|
||||||
|
'unidades' => $tirada,
|
||||||
|
'entregaPalets' => false
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Generamos el objeto a importar
|
||||||
|
$dataToImport = [
|
||||||
|
'selectedTirada' => $tirada,
|
||||||
|
'datosCabecera' => [
|
||||||
|
'titulo' => $titulo,
|
||||||
|
'autor' => null,
|
||||||
|
'isbn' => null,
|
||||||
|
'coleccion' => null,
|
||||||
|
'referenciaCliente' => $refCliente
|
||||||
|
],
|
||||||
|
'tirada' => [$tirada],
|
||||||
|
'tamanio' => [
|
||||||
|
'ancho' => $ancho,
|
||||||
|
'alto' => $alto
|
||||||
|
],
|
||||||
|
'tipo' => '',
|
||||||
|
'tipo_presupuesto_id' => $encuadernadoId,
|
||||||
|
'clienteId' => 40, // BUBOK ID
|
||||||
|
'isColor' => ($interiorTipo === 'color') ? 1 : 0,
|
||||||
|
'isHq' => 0,
|
||||||
|
'paginas' => $paginas,
|
||||||
|
'paginasColor' => ($interiorTipo === 'color') ? $paginas : 0,
|
||||||
|
'paginasCuadernillo' => 32,
|
||||||
|
'interior' => [
|
||||||
|
'papelInterior' => $papelInteriorId,
|
||||||
|
'gramajeInterior' => $gramajePapelInterior
|
||||||
|
],
|
||||||
|
'cubierta' => [
|
||||||
|
'papelCubierta' => 2, // 'EST2'
|
||||||
|
'carasCubierta' => $doscara ? 2 : 4,
|
||||||
|
'gramajeCubierta' => in_array($encuadernadoId, [1, 3]) ? 150 : 300, // 150 gramos para "fresado tapa dura" y "cosido tapa dura"
|
||||||
|
'solapas' => !empty($producto->cover->type->consolapas) ? 80 : 0,
|
||||||
|
'acabado' => $acabadoId,
|
||||||
|
'cabezada' => 'WHI',
|
||||||
|
'lomoRedondo' => 0
|
||||||
|
],
|
||||||
|
'guardas' => [],
|
||||||
|
'sobrecubierta' => [],
|
||||||
|
'faja' => null,
|
||||||
|
'comentarios_safekat' => 'URL COVER: ' . $producto->cover->file . "\nURL BODY: " . $producto->body->file,
|
||||||
|
|
||||||
|
'direcciones' => $direcciones
|
||||||
|
];
|
||||||
|
|
||||||
|
/*return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'message' => $dataToImport
|
||||||
|
]);*/
|
||||||
|
|
||||||
|
// 5. Guardar
|
||||||
|
try {
|
||||||
|
$presupuestocliente = new Presupuestocliente();
|
||||||
|
$response = $presupuestocliente->guardar($dataToImport);
|
||||||
|
|
||||||
|
if (!isset($response['sk_id'])) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 400,
|
||||||
|
'error' => 'Missing sk_id',
|
||||||
|
'message' => 'No se pudo crear el presupuesto.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 200,
|
||||||
|
'data' => [
|
||||||
|
'sk_id' => $response['sk_id'],
|
||||||
|
'sk_url' => $response['sk_url'] ?? null
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 500,
|
||||||
|
'error' => 'Server error',
|
||||||
|
'message' => 'Error inesperado',
|
||||||
|
'debug' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -44,11 +44,8 @@ class ImportadorCatalogo extends BaseResourceController
|
|||||||
{
|
{
|
||||||
|
|
||||||
$viewData = [
|
$viewData = [
|
||||||
'currentModule' => static::$controllerSlug,
|
|
||||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Importador.importadorCatalogoTitle')]),
|
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Importador.importadorCatalogoTitle')]),
|
||||||
'catalogoLibrosEntity' => new CatalogoLibroEntity(),
|
|
||||||
'usingServerSideDataTable' => true,
|
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||||
@ -244,7 +241,7 @@ class ImportadorCatalogo extends BaseResourceController
|
|||||||
|
|
||||||
'guardas' => [],
|
'guardas' => [],
|
||||||
'sobrecubierta' => $sobrecubierta,
|
'sobrecubierta' => $sobrecubierta,
|
||||||
'faja' => [],
|
//'faja' => null,
|
||||||
|
|
||||||
'entrega_taller' => 1,
|
'entrega_taller' => 1,
|
||||||
];
|
];
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Entities\Cliente;
|
namespace App\Entities\Clientes;
|
||||||
|
|
||||||
use CodeIgniter\Entity;
|
use CodeIgniter\Entity;
|
||||||
|
use App\Models\Clientes\ClienteModel;
|
||||||
|
use App\Models\Configuracion\PaisModel;
|
||||||
|
|
||||||
class ClienteDireccionesEntity extends \CodeIgniter\Entity\Entity
|
class ClienteDireccionesEntity extends \CodeIgniter\Entity\Entity
|
||||||
{
|
{
|
||||||
@ -23,4 +25,29 @@ class ClienteDireccionesEntity extends \CodeIgniter\Entity\Entity
|
|||||||
"pais_id" => "int",
|
"pais_id" => "int",
|
||||||
"cp" => "int",
|
"cp" => "int",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function getClienteNombre(): ?string
|
||||||
|
{
|
||||||
|
if (!$this->cliente_id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clienteModel = model(ClienteModel::class);
|
||||||
|
$cliente = $clienteModel->find($this->cliente_id);
|
||||||
|
|
||||||
|
return $cliente ? $cliente->nombre : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaisNombre(): ?string
|
||||||
|
{
|
||||||
|
if (!$this->pais_id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$paisModel = model(PaisModel::class);
|
||||||
|
$pais = $paisModel->find($this->pais_id);
|
||||||
|
|
||||||
|
return $pais ? $pais->nombre : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -722,6 +722,7 @@ return [
|
|||||||
|
|
||||||
"menu_importadores" => "Importadores",
|
"menu_importadores" => "Importadores",
|
||||||
"menu_importadores_catalogo" => "Desde catálogo",
|
"menu_importadores_catalogo" => "Desde catálogo",
|
||||||
|
"menu_importadores_bubok" => "Bubok",
|
||||||
|
|
||||||
"menu_catalogo" => "Catálogo",
|
"menu_catalogo" => "Catálogo",
|
||||||
"menu_catalogo_libros" => "Libros",
|
"menu_catalogo_libros" => "Libros",
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
return [
|
return [
|
||||||
'moduleTitle' => 'Importadores',
|
'moduleTitle' => 'Importadores',
|
||||||
'importadorCatalogoTitle' => 'Importador RA-MA Ediciones S.L.',
|
'importadorCatalogoTitle' => 'Importador RA-MA Ediciones S.L.',
|
||||||
|
'importadorBubokTitle' => 'Importador BUBOK Publishing S.L.',
|
||||||
'catalogo' => 'catálogo',
|
'catalogo' => 'catálogo',
|
||||||
'input' => 'ISBN',
|
'input' => 'ISBN',
|
||||||
'descripcion' => 'Título',
|
'descripcion' => 'Título',
|
||||||
@ -10,7 +11,8 @@ return [
|
|||||||
'cnt_pedida' => 'Unidades',
|
'cnt_pedida' => 'Unidades',
|
||||||
'precio_compra' => 'Precio Compra',
|
'precio_compra' => 'Precio Compra',
|
||||||
'importar' => 'Importar',
|
'importar' => 'Importar',
|
||||||
'subirArchivo' => 'Cargar Excel proporcionado por RA-MA',
|
'subirArchivoRama' => 'Cargar Excel proporcionado por RA-MA',
|
||||||
|
'subirArchivoBubok' => 'Cargar XML proporcionado por BUBOK',
|
||||||
|
|
||||||
'libro' => 'libro',
|
'libro' => 'libro',
|
||||||
'id' => 'ID',
|
'id' => 'ID',
|
||||||
|
|||||||
@ -70,6 +70,7 @@ return [
|
|||||||
'catalogoSection' => 'Catálogo',
|
'catalogoSection' => 'Catálogo',
|
||||||
'importadoresSection' => 'Importadores',
|
'importadoresSection' => 'Importadores',
|
||||||
'catalogoPermission' => 'Desde catálogo',
|
'catalogoPermission' => 'Desde catálogo',
|
||||||
|
'bubokPermission' => 'Bubok',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,103 @@
|
|||||||
|
<?= $this->include('themes/_commonPartialsBs/datatables') ?>
|
||||||
|
<?= $this->include('themes/_commonPartialsBs/sweetalert') ?>
|
||||||
|
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
|
||||||
|
|
||||||
|
<?= $this->section('content'); ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
|
||||||
|
<div class="card card-info">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3 class="card-title"><?= lang('Importador.importadorBubokTitle') ?></h3>
|
||||||
|
</div><!--//.card-header -->
|
||||||
|
|
||||||
|
<form id="catalogoLibroForm" class="card-body" method="post" action="#">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
|
||||||
|
<!-- card-body -->
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="xmlFile"
|
||||||
|
class="form-label"><?= lang('Importador.subirArchivoBubok') ?? 'Subir archivo XML' ?></label>
|
||||||
|
<input type="file" id="xmlFile" accept=".xml" class="form-control">
|
||||||
|
</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">
|
||||||
|
|
||||||
|
<table id="xmlTable" class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input type="checkbox" id="selectAll" /></th>
|
||||||
|
<th>Referencia</th>
|
||||||
|
<th>Título</th>
|
||||||
|
<th>Tamaño</th>
|
||||||
|
<th>Páginas</th>
|
||||||
|
<th>Tirada</th>
|
||||||
|
<th>Interior</th>
|
||||||
|
<th>Notas</th>
|
||||||
|
<th>Acciones</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th></th> <!-- No filtro para checkbox -->
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th> <!-- No filtro para notas -->
|
||||||
|
<th></th> <!-- No filtro para acciones -->
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div><!--//.card-body -->
|
||||||
|
<div class="card-footer">
|
||||||
|
|
||||||
|
</div><!--//.card-footer -->
|
||||||
|
</div><!--//.card -->
|
||||||
|
</div><!--//.col -->
|
||||||
|
</div><!--//.row -->
|
||||||
|
|
||||||
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?= $this->section('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/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||||
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
|
|
||||||
|
<?= $this->section('additionalExternalJs') ?>
|
||||||
|
<script
|
||||||
|
src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>"></script>
|
||||||
|
<script
|
||||||
|
src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.js") ?>"></script>
|
||||||
|
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.html5.min.js") ?>"></script>
|
||||||
|
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.print.min.js") ?>"></script>
|
||||||
|
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/jszip/jszip.min.js") ?>"></script>
|
||||||
|
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/pdfmake.min.js") ?>"
|
||||||
|
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
|
||||||
|
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||||
|
<script type="module" src="<?= site_url("assets/js/safekat/pages/importadores/bubok/bubok_tool.js") ?>"></script>
|
||||||
|
<?= $this->endSection() ?>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
<div class="col-md-6 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<label for="excelFile"
|
<label for="excelFile"
|
||||||
class="form-label"><?= lang('Importador.subirArchivo') ?? 'Subir archivo Excel' ?></label>
|
class="form-label"><?= lang('Importador.subirArchivoRama') ?? 'Subir archivo Excel' ?></label>
|
||||||
<input type="file" class="form-control" id="excelFile" name="excelFile"
|
<input type="file" class="form-control" id="excelFile" name="excelFile"
|
||||||
accept=".xlsx, .xls">
|
accept=".xlsx, .xls">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -20,7 +20,14 @@ if (auth()->user()->can('importadores.menu')) {
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
<?php if (auth()->user()->can('importadores.bubok')) { ?>
|
||||||
|
<li class="menu-item">
|
||||||
|
<a href="<?= route_to("importadorBubokTool") ?>" class="menu-link">
|
||||||
|
<?= lang("App.menu_importadores_bubok") ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,344 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
let dataTable;
|
||||||
|
let productosOriginales = [];
|
||||||
|
let datosComunesPedido = {};
|
||||||
|
|
||||||
|
document.getElementById('xmlFile').addEventListener('change', function (e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function (event) {
|
||||||
|
const xmlText = event.target.result;
|
||||||
|
parseXmlAndLoadTable(xmlText);
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
});
|
||||||
|
|
||||||
|
function parseXmlAndLoadTable(xmlText) {
|
||||||
|
let parser = new DOMParser();
|
||||||
|
let xmlDoc;
|
||||||
|
|
||||||
|
try {
|
||||||
|
xmlDoc = parser.parseFromString(xmlText, 'application/xml');
|
||||||
|
if (xmlDoc.getElementsByTagName('parsererror').length > 0) throw new Error('XML inválido');
|
||||||
|
} catch (e) {
|
||||||
|
Swal.fire('Error', 'No se pudo leer el XML.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
datosComunesPedido = {
|
||||||
|
orderNumber: xmlDoc.querySelector('orderNumber')?.textContent ?? '',
|
||||||
|
shipping: {
|
||||||
|
address: xmlDoc.querySelector('shippingData > address')?.textContent ?? '',
|
||||||
|
city: xmlDoc.querySelector('shippingData > city')?.textContent ?? '',
|
||||||
|
country: xmlDoc.querySelector('shippingData > country')?.textContent ?? '',
|
||||||
|
postalCode: xmlDoc.querySelector('shippingData > postalCode')?.textContent ?? '',
|
||||||
|
name: xmlDoc.querySelector('shippingData > name')?.textContent ?? '',
|
||||||
|
phone: xmlDoc.querySelector('shippingData > phone')?.textContent ?? ''
|
||||||
|
},
|
||||||
|
labelUrl: xmlDoc.querySelector('urlPdfSeur')?.textContent ?? ''
|
||||||
|
};
|
||||||
|
|
||||||
|
const products = Array.from(xmlDoc.getElementsByTagName('product'));
|
||||||
|
productosOriginales = products.map((prod, idx) => ({ index: idx, data: prod }));
|
||||||
|
|
||||||
|
const rows = products.map((product, index) => {
|
||||||
|
const id = product.querySelector('id')?.textContent ?? '';
|
||||||
|
const title = product.querySelector('title')?.textContent ?? '';
|
||||||
|
const pages = product.querySelector('body > pages')?.textContent ?? '';
|
||||||
|
const tirada = product.querySelector('amount')?.textContent ?? '';
|
||||||
|
|
||||||
|
let interior = 'Desconocido';
|
||||||
|
const colorNode = product.querySelector('body > color');
|
||||||
|
if (colorNode) {
|
||||||
|
const monochrome = colorNode.querySelector('Monochrome')?.textContent ?? '0';
|
||||||
|
const cmyk = colorNode.querySelector('CMYK')?.textContent ?? '0';
|
||||||
|
const semicolor = colorNode.querySelector('Semicolor')?.textContent ?? '0';
|
||||||
|
|
||||||
|
if (monochrome === '1') interior = 'Negro';
|
||||||
|
else if (cmyk === '1') interior = 'Color';
|
||||||
|
else if (semicolor === '1') interior = 'Semicolor';
|
||||||
|
}
|
||||||
|
|
||||||
|
let tamano = 'Desconocido';
|
||||||
|
const sizeTags = product.querySelectorAll('size > *');
|
||||||
|
sizeTags.forEach(tag => {
|
||||||
|
if (tag.textContent === '1') {
|
||||||
|
tamano = tag.tagName.replace(/^size/, '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
`<input type="checkbox" class="form-check-input select-row" checked>`,
|
||||||
|
`${datosComunesPedido.orderNumber} - ${id}`,
|
||||||
|
title,
|
||||||
|
tamano,
|
||||||
|
pages,
|
||||||
|
tirada,
|
||||||
|
interior,
|
||||||
|
'',
|
||||||
|
`<button type="button" class="btn btn-sm btn-outline-success importRow">Importar</button>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-danger deleteRow">Eliminar</button>`
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!$.fn.DataTable.isDataTable('#xmlTable')) {
|
||||||
|
const headerHtml = `
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input type="checkbox" id="selectAll" /></th>
|
||||||
|
<th>Referencia</th>
|
||||||
|
<th>Título</th>
|
||||||
|
<th>Tamaño</th>
|
||||||
|
<th>Páginas</th>
|
||||||
|
<th>Tirada</th>
|
||||||
|
<th>Interior</th>
|
||||||
|
<th>Notas</th>
|
||||||
|
<th>Acciones</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th></th><th></th><th></th><th></th><th></th>
|
||||||
|
<th></th><th></th><th></th><th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>`;
|
||||||
|
$('#xmlTable').html(headerHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataTable = $('#xmlTable').DataTable({
|
||||||
|
destroy: true,
|
||||||
|
data: rows,
|
||||||
|
orderCellsTop: true,
|
||||||
|
responsive: true,
|
||||||
|
scrollX: true,
|
||||||
|
dom: 'lfrtip',
|
||||||
|
language: {
|
||||||
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||||
|
},
|
||||||
|
order: [[1, 'asc']]
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#xmlTable thead tr:eq(1) th').each(function (i) {
|
||||||
|
if (![0, 7, 8].includes(i)) {
|
||||||
|
$(this).html('<input type="text" class="form-control form-control-sm" placeholder="Filtrar..." />');
|
||||||
|
$('input', this).on('keyup change', function () {
|
||||||
|
if (dataTable.column(i).search() !== this.value) {
|
||||||
|
dataTable.column(i).search(this.value).draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setupEventListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupEventListeners() {
|
||||||
|
$('#xmlTable tbody').off('click', '.deleteRow').on('click', '.deleteRow', function () {
|
||||||
|
dataTable.row($(this).parents('tr')).remove().draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#xmlTable tbody').off('click', '.importRow').on('click', '.importRow', async function () {
|
||||||
|
const $row = $(this).closest('tr');
|
||||||
|
const rowIndex = dataTable.row($row).index();
|
||||||
|
const xmlProduct = productosOriginales.find(p => p.index === rowIndex)?.data;
|
||||||
|
|
||||||
|
if (!xmlProduct) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/importador/bubok/importar-fila', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': '<?= csrf_hash() ?>'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
producto: xmlToJson(xmlProduct),
|
||||||
|
pedido: datosComunesPedido
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
const rowData = dataTable.row($row).data();
|
||||||
|
if (response.ok && result.status === 200) {
|
||||||
|
const skUrl = result.data?.sk_url?.replace('presupuestocliente', 'presupuestoadmin') ?? null;
|
||||||
|
const htmlLink = skUrl
|
||||||
|
? `<a href="${skUrl}" target="_blank" class="btn btn-sm btn-primary">Ver presupuesto</a>`
|
||||||
|
: 'Importado';
|
||||||
|
rowData[7] = htmlLink;
|
||||||
|
dataTable.row($row).data(rowData).draw(false);
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Importado correctamente',
|
||||||
|
html: skUrl
|
||||||
|
? `Se importó correctamente.<br><a href="${skUrl}" target="_blank" class="btn btn-primary mt-2">Ver presupuesto</a>`
|
||||||
|
: 'Importación realizada.',
|
||||||
|
icon: 'success',
|
||||||
|
confirmButtonText: 'Aceptar',
|
||||||
|
customClass: { confirmButton: 'btn btn-success' }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
rowData[7] = `<span class="badge bg-danger">${result.message ?? 'Error inesperado'}</span>`;
|
||||||
|
dataTable.row($row).data(rowData).draw(false);
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: result.message ?? 'Hubo un error al importar esta fila.',
|
||||||
|
icon: 'error',
|
||||||
|
confirmButtonText: 'Aceptar',
|
||||||
|
customClass: { confirmButton: 'btn btn-danger' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
dataTable.row($row).data(rowData).draw(false);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
Swal.fire('Error', 'Error de comunicación con el servidor.', 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#selectAll').off('change').on('change', function () {
|
||||||
|
const checked = $(this).is(':checked');
|
||||||
|
$('#xmlTable tbody input.select-row:enabled').prop('checked', checked);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function xmlToJson(xmlNode) {
|
||||||
|
// Si es nodo de texto
|
||||||
|
if (xmlNode.nodeType === 3) {
|
||||||
|
return xmlNode.nodeValue.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
let obj = {};
|
||||||
|
|
||||||
|
// Procesar atributos si existen
|
||||||
|
if (xmlNode.attributes && xmlNode.attributes.length > 0) {
|
||||||
|
for (let attr of xmlNode.attributes) {
|
||||||
|
obj[`@${attr.name}`] = attr.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesar hijos
|
||||||
|
if (xmlNode.hasChildNodes()) {
|
||||||
|
const children = Array.from(xmlNode.childNodes).filter(n => n.nodeType !== 8); // ignorar comentarios
|
||||||
|
|
||||||
|
// Si el único hijo es texto, devolver como string
|
||||||
|
if (children.length === 1 && children[0].nodeType === 3) {
|
||||||
|
return children[0].nodeValue.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesar nodos hijos normalmente
|
||||||
|
children.forEach(child => {
|
||||||
|
const name = child.nodeName;
|
||||||
|
const value = xmlToJson(child);
|
||||||
|
|
||||||
|
if (obj[name]) {
|
||||||
|
if (!Array.isArray(obj[name])) {
|
||||||
|
obj[name] = [obj[name]];
|
||||||
|
}
|
||||||
|
obj[name].push(value);
|
||||||
|
} else {
|
||||||
|
obj[name] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('importBtn').addEventListener('click', async function () {
|
||||||
|
if (!dataTable || dataTable.rows().count() === 0) {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Atención',
|
||||||
|
text: 'Primero debes cargar un archivo XML válido.',
|
||||||
|
icon: 'warning',
|
||||||
|
confirmButtonText: 'Aceptar',
|
||||||
|
customClass: { confirmButton: 'btn btn-warning' }
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filasSeleccionadas = [];
|
||||||
|
|
||||||
|
dataTable.rows().every(function () {
|
||||||
|
const node = this.node();
|
||||||
|
const checkbox = $(node).find('input.select-row');
|
||||||
|
if (checkbox.length > 0 && checkbox.is(':checked') && !checkbox.is(':disabled')) {
|
||||||
|
filasSeleccionadas.push(this.index());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filasSeleccionadas.length === 0) {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Atención',
|
||||||
|
text: 'No hay filas seleccionadas.',
|
||||||
|
icon: 'warning',
|
||||||
|
confirmButtonText: 'Aceptar',
|
||||||
|
customClass: { confirmButton: 'btn btn-warning' }
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: '¿Importar seleccionados?',
|
||||||
|
text: `Se van a importar ${filasSeleccionadas.length} filas.`,
|
||||||
|
icon: 'question',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: 'Sí, importar',
|
||||||
|
cancelButtonText: 'Cancelar',
|
||||||
|
reverseButtons: true,
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary',
|
||||||
|
cancelButton: 'btn btn-secondary'
|
||||||
|
}
|
||||||
|
}).then(async (result) => {
|
||||||
|
if (!result.isConfirmed) return;
|
||||||
|
|
||||||
|
for (const i of filasSeleccionadas) {
|
||||||
|
const productXml = productosOriginales.find(p => p.index === i)?.data;
|
||||||
|
if (!productXml) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/importador/bubok/importar-fila', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': '<?= csrf_hash() ?>'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
producto: xmlToJson(productXml),
|
||||||
|
pedido: datosComunesPedido
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
const rowNode = dataTable.row(i).node();
|
||||||
|
const rowData = dataTable.row(i).data();
|
||||||
|
|
||||||
|
if (response.ok && result.status === 200) {
|
||||||
|
const skUrl = result.data?.sk_url?.replace('presupuestocliente', 'presupuestoadmin') ?? null;
|
||||||
|
rowData[7] = skUrl
|
||||||
|
? `<a href="${skUrl}" target="_blank" class="btn btn-sm btn-primary">Ver presupuesto</a>`
|
||||||
|
: '<span class="badge bg-success">Importado</span>';
|
||||||
|
} else {
|
||||||
|
rowData[7] = `<span class="badge bg-danger">${result.message ?? 'Error desconocido'}</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
dataTable.row(rowNode).data(rowData).draw(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Importación fallida:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Importación finalizada',
|
||||||
|
text: 'Se han procesado todas las filas seleccionadas.',
|
||||||
|
icon: 'success',
|
||||||
|
confirmButtonText: 'Aceptar',
|
||||||
|
customClass: { confirmButton: 'btn btn-success' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user