/* AGS 92 B2B – DPH náplasť pre trhy s prenesením daňovej povinnosti (CZ, HU, PL, EN). * Na SK nerobí nič. Skrýva sumy "s DPH", stĺpec DPH v košíku prepíše na 0 %, * doplní vetu o reverse charge. Iba zobrazenie – nič neposiela na server. * Vypnutie: odstrániť include z pätičky (Container 22, property[15]). */ (function () { 'use strict'; var lang = (location.pathname.split('/')[1] || '').toLowerCase(); if (!/^(cz|hu|pl|com)$/.test(lang)) return; /* SK a admin: nič */ if (window.__agsDphLoaded) return; window.__agsDphLoaded = true; var NOTES = { cz: 'Ceny jsou uvedeny bez DPH. DPH se neúčtuje – přenesení daňové povinnosti (reverse charge).', hu: 'Az árak ÁFA nélkül értendők. ÁFA nem kerül felszámításra – fordított adózás (reverse charge).', pl: 'Ceny netto. VAT nie jest naliczany – odwrotne obciążenie (reverse charge).', en: 'Prices are net. VAT is not charged – reverse charge.' }; var NET_LABEL = { cz: 'bez DPH', hu: 'ÁFA nélkül', pl: 'netto', en: 'excl. VAT' }; var NOTE = NOTES[lang] || NOTES.en; var NETL = NET_LABEL[lang] || NET_LABEL.en; var VAT_HDR = /^(DPH|ÁFA|VAT|Sazba DPH|Sadzba DPH|ÁFA kulcs|Stawka VAT|VAT rate)\s*(%|\(%\))?$/i; function txt(e) { return (e && e.textContent || '').replace(/\s+/g, ' ').trim(); } function makeNote(cls) { var d = document.createElement('div'); d.className = 'ags-vat-note ' + (cls || ''); d.setAttribute('style', 'margin:10px 0;padding:8px 12px;border-left:3px solid #4a7bd0;background:#eef3fc;color:#1f3b6e;font-size:13px;line-height:1.4;'); d.textContent = NOTE; return d; } function addNoteAfter(el, key) { if (!el || !el.parentNode) return; if (el.parentNode.querySelector('.ags-vat-note.' + key)) return; el.parentNode.insertBefore(makeNote(key), el.nextSibling); } /* 1. Mini košík v hlavičke (aj po AJAX prepísaní) */ function miniCart() { var boxes = document.querySelectorAll('#mini-cart, .shopping-cart-small, .eshop-small-cart'); for (var i = 0; i < boxes.length; i++) { var box = boxes[i]; var gross = box.querySelector('.total-price-formated'); var net = box.querySelector('.total-price-no-vat-formated'); if (!gross || !net) continue; var nv = txt(net); if (nv && txt(gross) !== nv) gross.textContent = nv; if (!gross.nextSibling || !gross.nextSibling.classList || !gross.nextSibling.classList.contains('ags-vat-net')) { var lbl = document.createElement('small'); lbl.className = 'ags-vat-net'; lbl.textContent = ' ' + NETL; gross.parentNode.insertBefore(lbl, gross.nextSibling); } /* schovať duplicitný riadok "539 Kč bez DPH" pod tým */ var small = net.closest('small'); if (small && !small.classList.contains('ags-vat-done')) { small.classList.add('ags-vat-done'); var n = small.firstChild; while (n) { var next = n.nextSibling; if (n.nodeType === 1 && n.tagName === 'BR') { n.parentNode.removeChild(n); break; } if (n.nodeType === 3) n.textContent = ''; else if (n.nodeType === 1) n.style.display = 'none'; n = next; } } } } /* 2. Košík: stĺpec DPH → 0 %, riadok "DPH 23%" v súhrne preč, poznámka */ function cartPage() { var tables = document.querySelectorAll('table.basket_table'); for (var t = 0; t < tables.length; t++) { var tbl = tables[t]; var ths = tbl.querySelectorAll('thead th'); var idx = -1; for (var h = 0; h < ths.length; h++) if (VAT_HDR.test(txt(ths[h]))) { idx = h; break; } if (idx < 0) continue; var rows = tbl.querySelectorAll('tbody tr'); for (var r = 0; r < rows.length; r++) { var cells = rows[r].children; var td = cells[idx]; if (td && td.tagName === 'TD' && /^\d+([.,]\d+)?\s*%?$/.test(txt(td)) && txt(td) !== '0 %') { td.textContent = '0\u00a0%'; td.style.whiteSpace = 'nowrap'; } } } var sums = document.querySelectorAll('table.summary'); for (var s = 0; s < sums.length; s++) { var trs = sums[s].querySelectorAll('tfoot tr, tbody tr'); for (var k = 0; k < trs.length; k++) { var tr = trs[k]; if (tr.style.display === 'none') continue; var hasVat = false; var tds = tr.querySelectorAll('td'); for (var c = 0; c < tds.length; c++) { var cl = ' ' + (tds[c].className || '') + ' '; if (/ vat-\d+-formated /.test(cl)) hasVat = true; } if (hasVat) tr.style.display = 'none'; } addNoteAfter(sums[s], 'ags-note-cart'); } } /* 3. Dodacie údaje: "663 Kč s DPH" preč */ function deliveryPage() { var g = document.querySelectorAll('.bt-cart-total-total-price.total-price-formated'); for (var i = 0; i < g.length; i++) { g[i].style.display = 'none'; var net = g[i].parentNode && g[i].parentNode.querySelector('.total-price-no-vat-formated'); if (net) addNoteAfter(net, 'ags-note-delivery'); } } /* 4. Súhrn objednávky: poznámka nad tlačidlom OBJEDNAŤ */ function summaryPage() { var f = document.querySelector('input[name="b2_b_summary_form"]'); if (!f) return; var main = document.querySelector('main') || document.body; var tbls = main.querySelectorAll('table.table-striped'); if (!tbls.length) tbls = main.querySelectorAll('table'); var tbl = tbls.length ? tbls[Math.min(1, tbls.length - 1)] : null; /* 2. tabuľka = celková výška objednávky */ if (tbl) addNoteAfter(tbl, 'ags-note-summary'); } var timer = null; function run() { timer = null; try { miniCart(); cartPage(); deliveryPage(); summaryPage(); } catch (e) { /* fail-open */ } } function schedule() { if (!timer) timer = setTimeout(run, 60); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', run); else run(); if (window.MutationObserver) { new MutationObserver(schedule).observe(document.documentElement, { childList: true, subtree: true, characterData: true }); } window.addEventListener('load', run); })();