From 59609df471565303d7c6b7be37f5159e7d347fb5 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Fri, 9 May 2025 13:54:41 +0200 Subject: [PATCH 1/2] =?UTF-8?q?A=C3=B1adidas=20modificaciones=20para=20PDF?= =?UTF-8?q?=20y=20bug=20detectado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Importadores/ImportadorBubok.php | 24 ++-- ci4/app/Language/es/Importador.php | 2 +- .../bubok/viewImportadorBubokTool.php | 4 +- .../pages/importadores/bubok/bubok_tool.js | 113 +++++++++++------- 4 files changed, 93 insertions(+), 50 deletions(-) diff --git a/ci4/app/Controllers/Importadores/ImportadorBubok.php b/ci4/app/Controllers/Importadores/ImportadorBubok.php index 02a8e2a4..39ca1535 100644 --- a/ci4/app/Controllers/Importadores/ImportadorBubok.php +++ b/ci4/app/Controllers/Importadores/ImportadorBubok.php @@ -277,6 +277,15 @@ class ImportadorBubok extends BaseResourceController ] ]; + // Recalcular calidad (isColor y isHq) en funcion del cliente + [$isColor, $isHq] = PresupuestoService::getCalidad( + 'importador-bubok', + null, + ((trim(strtolower($interiorTipo)) === 'color') ? 1 : 0), + 0, + intval($tirada ?? 0) + ); + // Generamos el objeto a importar $dataToImport = [ 'selectedTirada' => $tirada, @@ -295,8 +304,8 @@ class ImportadorBubok extends BaseResourceController 'tipo' => '', 'tipo_presupuesto_id' => $encuadernadoId, 'clienteId' => 40, // BUBOK ID - 'isColor' => ($interiorTipo === 'color') ? 1 : 0, - 'isHq' => 0, + 'isColor' => $isColor, + 'isHq' => $isHq, 'paginas' => $paginas, 'paginasColor' => ($interiorTipo === 'color') ? $paginas : 0, 'paginasCuadernillo' => 32, @@ -317,16 +326,17 @@ class ImportadorBubok extends BaseResourceController 'sobrecubierta' => [], 'faja' => null, - 'entrega_taller' => 1, - //'direcciones' => $direcciones, las direcciones que aparecen no se añaden, ya que la recogida la hacen ellos con su empresa de mensajeria + 'direcciones' => $direcciones, 'ivaReducido' => 1, ]; - /*return $this->respond([ + return $this->respond([ 'status' => 400, - 'message' => $dataToImport - ]);*/ + 'message' => $dataToImport, + 'interiorTipo' => $interiorTipo, + 'isColor' => $isColor + ]); // 5. Guardar try { diff --git a/ci4/app/Language/es/Importador.php b/ci4/app/Language/es/Importador.php index 925076fc..5f4f0ad0 100644 --- a/ci4/app/Language/es/Importador.php +++ b/ci4/app/Language/es/Importador.php @@ -12,7 +12,7 @@ return [ 'precio_compra' => 'Precio Compra', 'importar' => 'Importar', 'subirArchivoRama' => 'Cargar Excel proporcionado por RA-MA', - 'subirArchivoBubok' => 'Cargar XML proporcionado por BUBOK', + 'subirArchivoBubok' => 'Cargar ZIP proporcionado por BUBOK', 'libro' => 'libro', 'id' => 'ID', diff --git a/ci4/app/Views/themes/vuexy/form/importador/bubok/viewImportadorBubokTool.php b/ci4/app/Views/themes/vuexy/form/importador/bubok/viewImportadorBubokTool.php index 4db87bfe..1e89f976 100644 --- a/ci4/app/Views/themes/vuexy/form/importador/bubok/viewImportadorBubokTool.php +++ b/ci4/app/Views/themes/vuexy/form/importador/bubok/viewImportadorBubokTool.php @@ -22,8 +22,8 @@
- + class="form-label"> +
- ` - ]; - }); + // Obtener referencia del pedido + const refCliente = `${pedidoActual.orderNumber}-${id}`; + + // Validar fila con su propio pedido + const result = await validarProductoXml(product, pedidoActual); + + let checkboxHtml = ''; + let notaHtml = ''; + let actionBtnsHtml = ''; + + if (result.apto) { + checkboxHtml = ``; + notaHtml = ''; + actionBtnsHtml = ` +
+ + +
+ `; + } else { + checkboxHtml = ``; + notaHtml = `${result.reason}`; + actionBtnsHtml = ` +
+ No Apto + +
+ `; + } + + rows.push([checkboxHtml, refCliente, title, tamano, pages, tirada, interior, notaHtml, actionBtnsHtml]); + } if (!$.fn.DataTable.isDataTable('#xmlTable')) { - const headerHtml = ` - - - - Referencia - Título - Tamaño - Páginas - Tirada - Interior - Notas - Acciones - - - - - - `; - $('#xmlTable').html(headerHtml); + $('#xmlTable').html(` + + + + Referencia + Título + Tamaño + Páginas + Tirada + Interior + Notas + Acciones + + + + + + + `); } if (!dataTable) { @@ -141,6 +193,8 @@ document.addEventListener('DOMContentLoaded', function () { responsive: true, scrollX: true, dom: 'lfrtip', + pageLength: 25, + lengthMenu: [5, 10, 25, 50, 100, 250, 500], language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" }, @@ -163,8 +217,36 @@ document.addEventListener('DOMContentLoaded', function () { rows.forEach(row => dataTable.row.add(row)); dataTable.draw(false); } + + if (rows.length > 0) { + document.getElementById('importBtn').disabled = false; + } } + + async function validarProductoXml(productoXml, pedido) { + try { + const response = await fetch('/importador/bubok/validar-fila', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRF-TOKEN': '' + }, + body: JSON.stringify({ + producto: xmlToJson(productoXml), + pedido: pedido + }) + }); + + return await response.json(); + } catch (error) { + console.error('Error validando producto:', error); + return { apto: false, reason: 'Error conexión' }; + } + } + + + function setupEventListeners() { $('#xmlTable tbody').off('click', '.deleteRow').on('click', '.deleteRow', function () { dataTable.row($(this).parents('tr')).remove().draw(); @@ -173,9 +255,12 @@ document.addEventListener('DOMContentLoaded', function () { $('#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; + const productoObj = productosOriginales.find(p => p.index === rowIndex); - if (!xmlProduct) return; + if (!productoObj) return; + + const xmlProduct = productoObj.data; + const pedido = productoObj.pedido; try { const response = await fetch('/importador/bubok/importar-fila', { @@ -186,32 +271,46 @@ document.addEventListener('DOMContentLoaded', function () { }, body: JSON.stringify({ producto: xmlToJson(xmlProduct), - pedido: datosComunesPedido + pedido: pedido }) }); 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 - ? `Ver presupuesto` - : 'Importado'; - rowData[7] = htmlLink; + const skId = result.data?.sk_id ?? ''; + + rowData[7] = skUrl + ? `Ver presupuesto (${skId})` + : `Importado (${skId})`; + dataTable.row($row).data(rowData).draw(false); + let html = skUrl + ? `La fila se importó exitosamente.

Ver presupuesto (${skId})` + : `La fila se importó exitosamente. (${skId})`; + + let icon = 'success'; + + if (result.price_warning) { + html = skUrl + ? `La fila se importó con éxito, pero el precio fue ajustado por debajo de costes.

Ver presupuesto (${skId})` + : `La fila se importó con advertencia de coste. (${skId})`; + icon = 'warning'; + } + Swal.fire({ title: 'Importado correctamente', - html: skUrl - ? `Se importó correctamente.
Ver presupuesto` - : 'Importación realizada.', - icon: 'success', + html: html, + icon: icon, confirmButtonText: 'Aceptar', customClass: { confirmButton: 'btn btn-success' } }); + } else { - rowData[7] = `${result.message ?? 'Error inesperado'}`; + rowData[7] = `${result.message ?? 'Error desconocido'}`; dataTable.row($row).data(rowData).draw(false); Swal.fire({ @@ -222,15 +321,14 @@ document.addEventListener('DOMContentLoaded', function () { customClass: { confirmButton: 'btn btn-danger' } }); } - - dataTable.row($row).data(rowData).draw(false); - - } catch (err) { - console.error(err); + } catch (error) { + console.error('Importación fallida:', error); 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); @@ -329,8 +427,11 @@ document.addEventListener('DOMContentLoaded', function () { if (!result.isConfirmed) return; for (const i of filasSeleccionadas) { - const productXml = productosOriginales.find(p => p.index === i)?.data; - if (!productXml) continue; + const productoObj = productosOriginales.find(p => p.index === i); + if (!productoObj) continue; + + const productXml = productoObj.data; + const pedido = productoObj.pedido; try { const response = await fetch('/importador/bubok/importar-fila', { @@ -341,7 +442,7 @@ document.addEventListener('DOMContentLoaded', function () { }, body: JSON.stringify({ producto: xmlToJson(productXml), - pedido: datosComunesPedido + pedido: pedido }) }); @@ -351,9 +452,10 @@ document.addEventListener('DOMContentLoaded', function () { if (response.ok && result.status === 200) { const skUrl = result.data?.sk_url?.replace('presupuestocliente', 'presupuestoadmin') ?? null; + const skId = result.data?.sk_id ?? ''; rowData[7] = skUrl - ? `Ver presupuesto` - : 'Importado'; + ? `Ver presupuesto (${skId})` + : `Importado (${skId})`; } else { rowData[7] = `${result.message ?? 'Error desconocido'}`; }