mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadidas modificaciones para PDF y bug detectado
This commit is contained in:
@ -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
|
// Generamos el objeto a importar
|
||||||
$dataToImport = [
|
$dataToImport = [
|
||||||
'selectedTirada' => $tirada,
|
'selectedTirada' => $tirada,
|
||||||
@ -295,8 +304,8 @@ class ImportadorBubok extends BaseResourceController
|
|||||||
'tipo' => '',
|
'tipo' => '',
|
||||||
'tipo_presupuesto_id' => $encuadernadoId,
|
'tipo_presupuesto_id' => $encuadernadoId,
|
||||||
'clienteId' => 40, // BUBOK ID
|
'clienteId' => 40, // BUBOK ID
|
||||||
'isColor' => ($interiorTipo === 'color') ? 1 : 0,
|
'isColor' => $isColor,
|
||||||
'isHq' => 0,
|
'isHq' => $isHq,
|
||||||
'paginas' => $paginas,
|
'paginas' => $paginas,
|
||||||
'paginasColor' => ($interiorTipo === 'color') ? $paginas : 0,
|
'paginasColor' => ($interiorTipo === 'color') ? $paginas : 0,
|
||||||
'paginasCuadernillo' => 32,
|
'paginasCuadernillo' => 32,
|
||||||
@ -317,16 +326,17 @@ class ImportadorBubok extends BaseResourceController
|
|||||||
'sobrecubierta' => [],
|
'sobrecubierta' => [],
|
||||||
'faja' => null,
|
'faja' => null,
|
||||||
|
|
||||||
'entrega_taller' => 1,
|
'direcciones' => $direcciones,
|
||||||
//'direcciones' => $direcciones, las direcciones que aparecen no se añaden, ya que la recogida la hacen ellos con su empresa de mensajeria
|
|
||||||
|
|
||||||
'ivaReducido' => 1,
|
'ivaReducido' => 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
/*return $this->respond([
|
return $this->respond([
|
||||||
'status' => 400,
|
'status' => 400,
|
||||||
'message' => $dataToImport
|
'message' => $dataToImport,
|
||||||
]);*/
|
'interiorTipo' => $interiorTipo,
|
||||||
|
'isColor' => $isColor
|
||||||
|
]);
|
||||||
|
|
||||||
// 5. Guardar
|
// 5. Guardar
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ return [
|
|||||||
'precio_compra' => 'Precio Compra',
|
'precio_compra' => 'Precio Compra',
|
||||||
'importar' => 'Importar',
|
'importar' => 'Importar',
|
||||||
'subirArchivoRama' => 'Cargar Excel proporcionado por RA-MA',
|
'subirArchivoRama' => 'Cargar Excel proporcionado por RA-MA',
|
||||||
'subirArchivoBubok' => 'Cargar XML proporcionado por BUBOK',
|
'subirArchivoBubok' => 'Cargar ZIP proporcionado por BUBOK',
|
||||||
|
|
||||||
'libro' => 'libro',
|
'libro' => 'libro',
|
||||||
'id' => 'ID',
|
'id' => 'ID',
|
||||||
|
|||||||
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
<div class="col-md-6 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<label for="xmlFile"
|
<label for="xmlFile"
|
||||||
class="form-label"><?= lang('Importador.subirArchivoBubok') ?? 'Subir archivo XML' ?></label>
|
class="form-label"><?= lang('Importador.subirArchivoBubok') ?? 'Subir archivo ZIP' ?></label>
|
||||||
<input type="file" id="xmlFile" accept=".xml" class="form-control">
|
<input type="file" id="xmlFile" accept=".zip" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3 d-flex align-items-end">
|
<div class="col-md-4 mb-3 d-flex align-items-end">
|
||||||
<button type="button" id="importBtn" class="btn btn-success w-100">
|
<button type="button" id="importBtn" class="btn btn-success w-100">
|
||||||
|
|||||||
@ -5,14 +5,37 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
|
|
||||||
document.getElementById('xmlFile').addEventListener('change', function (e) {
|
document.getElementById('xmlFile').addEventListener('change', function (e) {
|
||||||
const file = e.target.files[0];
|
const file = e.target.files[0];
|
||||||
if (!file) return;
|
if (!file || !file.name.endsWith('.zip')) {
|
||||||
|
Swal.fire('Error', 'Selecciona un archivo .zip válido.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = function (event) {
|
reader.onload = async function (event) {
|
||||||
const xmlText = event.target.result;
|
try {
|
||||||
parseXmlAndLoadTable(xmlText);
|
const zip = await JSZip.loadAsync(event.target.result);
|
||||||
|
const xmlFiles = Object.values(zip.files).filter(f =>
|
||||||
|
f.name.endsWith('.xml') && !f.name.startsWith('__MACOSX/')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (xmlFiles.length === 0) {
|
||||||
|
Swal.fire('Error', 'El ZIP no contiene archivos XML.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of xmlFiles) {
|
||||||
|
const content = await file.async('text');
|
||||||
|
parseXmlAndLoadTable(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
Swal.fire('Éxito', `${xmlFiles.length} archivos XML cargados.`, 'success');
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
Swal.fire('Error', 'No se pudo procesar el ZIP.', 'error');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
|
||||||
|
reader.readAsArrayBuffer(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseXmlAndLoadTable(xmlText) {
|
function parseXmlAndLoadTable(xmlText) {
|
||||||
@ -41,9 +64,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const products = Array.from(xmlDoc.getElementsByTagName('product'));
|
const products = Array.from(xmlDoc.getElementsByTagName('product'));
|
||||||
productosOriginales = products.map((prod, idx) => ({ index: idx, data: prod }));
|
const offset = productosOriginales.length;
|
||||||
|
|
||||||
|
products.forEach((prod, idx) => {
|
||||||
|
productosOriginales.push({ index: offset + idx, data: prod });
|
||||||
|
});
|
||||||
|
|
||||||
const rows = products.map((product, index) => {
|
const rows = products.map((product, index) => {
|
||||||
|
const globalIndex = offset + index;
|
||||||
const id = product.querySelector('id')?.textContent ?? '';
|
const id = product.querySelector('id')?.textContent ?? '';
|
||||||
const title = product.querySelector('title')?.textContent ?? '';
|
const title = product.querySelector('title')?.textContent ?? '';
|
||||||
const pages = product.querySelector('body > pages')?.textContent ?? '';
|
const pages = product.querySelector('body > pages')?.textContent ?? '';
|
||||||
@ -105,31 +133,36 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
$('#xmlTable').html(headerHtml);
|
$('#xmlTable').html(headerHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataTable = $('#xmlTable').DataTable({
|
if (!dataTable) {
|
||||||
destroy: true,
|
dataTable = $('#xmlTable').DataTable({
|
||||||
data: rows,
|
destroy: true,
|
||||||
orderCellsTop: true,
|
data: rows,
|
||||||
responsive: true,
|
orderCellsTop: true,
|
||||||
scrollX: true,
|
responsive: true,
|
||||||
dom: 'lfrtip',
|
scrollX: true,
|
||||||
language: {
|
dom: 'lfrtip',
|
||||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
language: {
|
||||||
},
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||||
order: [[1, 'asc']]
|
},
|
||||||
});
|
order: [[1, 'asc']]
|
||||||
|
});
|
||||||
|
|
||||||
$('#xmlTable thead tr:eq(1) th').each(function (i) {
|
$('#xmlTable thead tr:eq(1) th').each(function (i) {
|
||||||
if (![0, 7, 8].includes(i)) {
|
if (![0, 7, 8].includes(i)) {
|
||||||
$(this).html('<input type="text" class="form-control form-control-sm" placeholder="Filtrar..." />');
|
$(this).html('<input type="text" class="form-control form-control-sm" placeholder="Filtrar..." />');
|
||||||
$('input', this).on('keyup change', function () {
|
$('input', this).on('keyup change', function () {
|
||||||
if (dataTable.column(i).search() !== this.value) {
|
if (dataTable.column(i).search() !== this.value) {
|
||||||
dataTable.column(i).search(this.value).draw();
|
dataTable.column(i).search(this.value).draw();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setupEventListeners();
|
setupEventListeners();
|
||||||
|
} else {
|
||||||
|
rows.forEach(row => dataTable.row.add(row));
|
||||||
|
dataTable.draw(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupEventListeners() {
|
function setupEventListeners() {
|
||||||
@ -258,9 +291,9 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const filasSeleccionadas = [];
|
const filasSeleccionadas = [];
|
||||||
|
|
||||||
dataTable.rows().every(function () {
|
dataTable.rows().every(function () {
|
||||||
const node = this.node();
|
const node = this.node();
|
||||||
const checkbox = $(node).find('input.select-row');
|
const checkbox = $(node).find('input.select-row');
|
||||||
@ -268,7 +301,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
filasSeleccionadas.push(this.index());
|
filasSeleccionadas.push(this.index());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (filasSeleccionadas.length === 0) {
|
if (filasSeleccionadas.length === 0) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: 'Atención',
|
title: 'Atención',
|
||||||
@ -279,7 +312,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: '¿Importar seleccionados?',
|
title: '¿Importar seleccionados?',
|
||||||
text: `Se van a importar ${filasSeleccionadas.length} filas.`,
|
text: `Se van a importar ${filasSeleccionadas.length} filas.`,
|
||||||
@ -294,11 +327,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
}
|
}
|
||||||
}).then(async (result) => {
|
}).then(async (result) => {
|
||||||
if (!result.isConfirmed) return;
|
if (!result.isConfirmed) return;
|
||||||
|
|
||||||
for (const i of filasSeleccionadas) {
|
for (const i of filasSeleccionadas) {
|
||||||
const productXml = productosOriginales.find(p => p.index === i)?.data;
|
const productXml = productosOriginales.find(p => p.index === i)?.data;
|
||||||
if (!productXml) continue;
|
if (!productXml) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/importador/bubok/importar-fila', {
|
const response = await fetch('/importador/bubok/importar-fila', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -311,11 +344,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
pedido: datosComunesPedido
|
pedido: datosComunesPedido
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
const rowNode = dataTable.row(i).node();
|
const rowNode = dataTable.row(i).node();
|
||||||
const rowData = dataTable.row(i).data();
|
const rowData = dataTable.row(i).data();
|
||||||
|
|
||||||
if (response.ok && result.status === 200) {
|
if (response.ok && result.status === 200) {
|
||||||
const skUrl = result.data?.sk_url?.replace('presupuestocliente', 'presupuestoadmin') ?? null;
|
const skUrl = result.data?.sk_url?.replace('presupuestocliente', 'presupuestoadmin') ?? null;
|
||||||
rowData[7] = skUrl
|
rowData[7] = skUrl
|
||||||
@ -324,13 +357,13 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
} else {
|
} else {
|
||||||
rowData[7] = `<span class="badge bg-danger">${result.message ?? 'Error desconocido'}</span>`;
|
rowData[7] = `<span class="badge bg-danger">${result.message ?? 'Error desconocido'}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
dataTable.row(rowNode).data(rowData).draw(false);
|
dataTable.row(rowNode).data(rowData).draw(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Importación fallida:', error);
|
console.error('Importación fallida:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: 'Importación finalizada',
|
title: 'Importación finalizada',
|
||||||
text: 'Se han procesado todas las filas seleccionadas.',
|
text: 'Se han procesado todas las filas seleccionadas.',
|
||||||
@ -340,5 +373,5 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user