diff --git a/pos/static/js/catalog.js b/pos/static/js/catalog.js index 6fbf960..fd7e798 100644 --- a/pos/static/js/catalog.js +++ b/pos/static/js/catalog.js @@ -2148,6 +2148,31 @@ } } + async function downloadPriceTemplate() { + try { + var res = await fetch('/pos/api/supplier-catalog/prices/template', { + headers: { 'Authorization': 'Bearer ' + token } + }); + if (!res.ok) { + var data = await res.json().catch(function() { return {}; }); + if (uploadPricesStatus) uploadPricesStatus.innerHTML = '' + esc(data.error || 'Error al descargar plantilla') + ''; + return; + } + var blob = await res.blob(); + var url = URL.createObjectURL(blob); + var a = document.createElement('a'); + a.href = url; + a.download = 'supplier_prices_template.csv'; + document.body.appendChild(a); + a.click(); + a.remove(); + URL.revokeObjectURL(url); + if (uploadPricesStatus) uploadPricesStatus.innerHTML = '✓ Plantilla descargada.'; + } catch (e) { + if (uploadPricesStatus) uploadPricesStatus.innerHTML = 'Error de red: ' + esc(e.message) + ''; + } + } + function shouldShowUploadPricesButton() { try { var user = JSON.parse(localStorage.getItem('pos_employee') || '{}'); @@ -2180,6 +2205,7 @@ openUploadPricesModal: openUploadPricesModal, closeUploadPricesModal: closeUploadPricesModal, submitUploadPrices: submitUploadPrices, + downloadPriceTemplate: downloadPriceTemplate, }; // ─── INIT ─── diff --git a/pos/templates/catalog.html b/pos/templates/catalog.html index a426d8d..0148f0f 100644 --- a/pos/templates/catalog.html +++ b/pos/templates/catalog.html @@ -294,8 +294,8 @@