From 77e45bdc1eeaada0a431addc7271e7597f9c2ca5 Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Thu, 2 Apr 2026 07:41:58 +0000 Subject: [PATCH] feat(pos): cross-references en detalle de producto de inventario Al abrir el detalle de un producto, se cargan automaticamente: - Disponibilidad en bodegas (stock + precio) - Partes equivalentes aftermarket (cross-references del catalogo TecDoc) Usa catalog_part_id o busqueda por part_number contra el catalogo central. Co-Authored-By: Claude Opus 4.6 (1M context) --- pos/static/js/inventory.js | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/pos/static/js/inventory.js b/pos/static/js/inventory.js index b16199f..f2ed69c 100644 --- a/pos/static/js/inventory.js +++ b/pos/static/js/inventory.js @@ -470,6 +470,77 @@ html += '
Precio 3$' + fmt(data.price_3) + '
'; html += ''; + // Cross-references section + html += '
Cross-References / Equivalencias
'; + html += '
'; + html += '

Cargando equivalencias...

'; + html += '
'; + + // Load cross-references from catalog API + var partNumber = data.part_number; + var catalogPartId = data.catalog_part_id; + (function loadCrossRefs() { + // Try catalog part detail if we have catalog_part_id + var url = catalogPartId + ? '/pos/api/catalog/part/' + catalogPartId + : '/pos/api/catalog/search?q=' + encodeURIComponent(partNumber); + + fetch(url, { headers: { 'Authorization': 'Bearer ' + token } }) + .then(function(r) { return r.json(); }) + .then(function(d) { + var el = document.getElementById('crossRefContent'); + if (!el) return; + + var alternatives = d.alternatives || []; + var bodegas = d.bodegas || []; + + // If it was a search, get alternatives from first result + if (!catalogPartId && d.data && d.data.length > 0) { + // Fetch detail for first match + fetch('/pos/api/catalog/part/' + d.data[0].id_part, { headers: { 'Authorization': 'Bearer ' + token } }) + .then(function(r2) { return r2.json(); }) + .then(function(d2) { + renderCrossRefs(el, d2.alternatives || [], d2.bodegas || []); + }) + .catch(function() { el.innerHTML = '

Sin conexion al catalogo.

'; }); + return; + } + + renderCrossRefs(el, alternatives, bodegas); + }) + .catch(function() { + var el = document.getElementById('crossRefContent'); + if (el) el.innerHTML = '

Sin conexion al catalogo central.

'; + }); + })(); + + function renderCrossRefs(el, alternatives, bodegas) { + var html2 = ''; + + if (bodegas && bodegas.length > 0) { + html2 += '
Disponible en Bodegas:
'; + html2 += ''; + bodegas.forEach(function(b) { + html2 += ''; + }); + html2 += '
BodegaStockPrecioUbicacion
' + esc(b.business_name || b.bodega || '') + '' + (b.stock || b.stock_quantity || 0) + '$' + fmt(b.price || 0) + '' + esc(b.location || b.warehouse_location || '') + '
'; + } + + if (alternatives && alternatives.length > 0) { + html2 += '
Partes Equivalentes (Aftermarket):
'; + html2 += ''; + alternatives.forEach(function(a) { + html2 += ''; + }); + html2 += '
No. ParteFabricanteNombre
' + esc(a.part_number || a.cross_reference_number || '') + '' + esc(a.manufacturer || a.source_ref || '') + '' + esc(a.name || a.name_aftermarket_parts || '') + '
'; + } + + if (!html2) { + html2 = '

No se encontraron equivalencias para esta parte.

'; + } + el.innerHTML = html2; + } + // Movement history html += '
Historial de Movimientos
'; if (!history.length) {