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
|
||||
$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 {
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -22,8 +22,8 @@
|
||||
|
||||
<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">
|
||||
class="form-label"><?= lang('Importador.subirArchivoBubok') ?? 'Subir archivo ZIP' ?></label>
|
||||
<input type="file" id="xmlFile" accept=".zip" 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">
|
||||
|
||||
@ -5,14 +5,37 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
document.getElementById('xmlFile').addEventListener('change', function (e) {
|
||||
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();
|
||||
reader.onload = function (event) {
|
||||
const xmlText = event.target.result;
|
||||
parseXmlAndLoadTable(xmlText);
|
||||
reader.onload = async function (event) {
|
||||
try {
|
||||
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) {
|
||||
@ -41,9 +64,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
};
|
||||
|
||||
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 globalIndex = offset + index;
|
||||
const id = product.querySelector('id')?.textContent ?? '';
|
||||
const title = product.querySelector('title')?.textContent ?? '';
|
||||
const pages = product.querySelector('body > pages')?.textContent ?? '';
|
||||
@ -105,6 +133,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
$('#xmlTable').html(headerHtml);
|
||||
}
|
||||
|
||||
if (!dataTable) {
|
||||
dataTable = $('#xmlTable').DataTable({
|
||||
destroy: true,
|
||||
data: rows,
|
||||
@ -130,6 +159,10 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
|
||||
setupEventListeners();
|
||||
} else {
|
||||
rows.forEach(row => dataTable.row.add(row));
|
||||
dataTable.draw(false);
|
||||
}
|
||||
}
|
||||
|
||||
function setupEventListeners() {
|
||||
|
||||
Reference in New Issue
Block a user