← back to depelo__bobine

Function bodies 262 total

All specs Real LLM only Function bodies
chiudiModale function · javascript · L1925-L1929 (5 LOC)
gb2/js/gb2-progressivi.js
    function chiudiModale() {
        document.getElementById('modalOrdiniOverlay').classList.remove('open');
        currentModalContext = null;
        ripristinaHeaderModale();
    }
onBiConfrontoYoYChange function · javascript · L1931-L1943 (13 LOC)
gb2/js/gb2-progressivi.js
    function onBiConfrontoYoYChange(e) {
        biState.isYoY = e.target.checked;
        if (biState.isYoY && biState.selectedYears.size === 0) biState.selectedYears.add(new Date().getFullYear().toString());
        const rawData = consumiCache[currentCodartConsumi];
        if (rawData) {
            const anniSet = new Set();
            (rawData.past || []).concat(rawData.future || []).forEach((r) => {
                if (r.DataMov && String(r.DataMov).length >= 4) anniSet.add(String(r.DataMov).slice(0, 4));
            });
            popolaSidebarAnni(Array.from(anniSet));
        }
        aggiornaGraficoBI();
    }
onBiGranularitaChange function · javascript · L1945-L1965 (21 LOC)
gb2/js/gb2-progressivi.js
    function onBiGranularitaChange() {
        const sel = document.getElementById('biGranularita');
        if (!sel) return;
        const v = sel.value;
        if (!granLevels.includes(v)) return;
        biState.granularity = v;
        if (!biState.isYoY) {
            if (biState.granularity === 'anno') biState.filter = null;
            else if (biState.granularity === 'mese' && biState.filter && biState.filter.length > 4) biState.filter = biState.filter.slice(0, 4);
        }

        const rawData = consumiCache[currentCodartConsumi];
        if (rawData) {
            const anniSet = new Set();
            (rawData.past || []).concat(rawData.future || []).forEach((r) => {
                if (r.DataMov && String(r.DataMov).length >= 4) anniSet.add(String(r.DataMov).slice(0, 4));
            });
            popolaSidebarAnni(Array.from(anniSet));
        }
        aggiornaGraficoBI();
    }
syncBiGranularitaSelect function · javascript · L1967-L1972 (6 LOC)
gb2/js/gb2-progressivi.js
    function syncBiGranularitaSelect() {
        const sel = document.getElementById('biGranularita');
        if (!sel) return;
        sel.disabled = false;
        if (granLevels.includes(biState.granularity)) sel.value = biState.granularity;
    }
onConsumiOlapWheel function · javascript · L1974-L1998 (25 LOC)
gb2/js/gb2-progressivi.js
    function onConsumiOlapWheel(e) {
        if (!consumiCache[currentCodartConsumi]) return;
        e.preventDefault();
        const gIdx = granLevels.indexOf(biState.granularity);

        if (e.deltaY > 0) {
            if (gIdx > 0) {
                biState.granularity = granLevels[gIdx - 1];
                if (!biState.isYoY) {
                    if (biState.granularity === 'anno') biState.filter = null;
                    else if (biState.granularity === 'mese' && biState.filter && biState.filter.length > 4) biState.filter = biState.filter.slice(0, 4);
                }
            }
        } else if (gIdx < granLevels.length - 1) {
            biState.granularity = granLevels[gIdx + 1];
        }

        const rawData = consumiCache[currentCodartConsumi];
        const anniSet = new Set();
        (rawData.past || []).concat(rawData.future || []).forEach((r) => {
            if (r.DataMov && String(r.DataMov).length >= 4) anniSet.add(String(r.DataMov).slice(0, 4));
     
chiudiModaleConsumi function · javascript · L2000-L2016 (17 LOC)
gb2/js/gb2-progressivi.js
    function chiudiModaleConsumi() {
        if (consumiMarathonController) {
            consumiMarathonController.abort();
            consumiMarathonController = null;
        }
        const overlay = document.getElementById('modalConsumiOverlay');
        if (overlay) overlay.classList.remove('open');
        const errEl = document.getElementById('modalConsumiError');
        if (errEl) {
            errEl.style.display = 'none';
            errEl.textContent = '';
        }
        if (consumiChartInstance) {
            consumiChartInstance.destroy();
            consumiChartInstance = null;
        }
    }
getMonday function · javascript · L2018-L2023 (6 LOC)
gb2/js/gb2-progressivi.js
    function getMonday(d) {
        const day = d.getDay() || 7;
        const res = new Date(d);
        res.setDate(d.getDate() - day + 1);
        return res;
    }
All rows scored by the Repobility analyzer (https://repobility.com)
buildSortKey function · javascript · L2025-L2042 (18 LOC)
gb2/js/gb2-progressivi.js
    function buildSortKey(dStr, gran) {
        const d = new Date(dStr);
        if (Number.isNaN(d.getTime())) return '';
        const y = d.getFullYear();
        const m = ('0' + (d.getMonth() + 1)).slice(-2);
        const day = ('0' + d.getDate()).slice(-2);
        const q = Math.ceil((d.getMonth() + 1) / 3);
        const s = Math.ceil((d.getMonth() + 1) / 6);
        if (gran === 'anno') return `${y}`;
        if (gran === 'semestre') return `${y}-S${s}`;
        if (gran === 'trimestre') return `${y}-Q${q}`;
        if (gran === 'mese') return `${y}-${m}`;
        if (gran === 'settimana') {
            const mon = getMonday(d);
            return `${mon.getFullYear()}-${('0' + (mon.getMonth() + 1)).slice(-2)}-${('0' + mon.getDate()).slice(-2)}`;
        }
        return `${y}-${m}-${day}`;
    }
yoyBucketKey function · javascript · L2044-L2060 (17 LOC)
gb2/js/gb2-progressivi.js
    function yoyBucketKey(dStr, gran) {
        const d = new Date(dStr);
        if (Number.isNaN(d.getTime())) return '';
        const m = ('0' + (d.getMonth() + 1)).slice(-2);
        if (gran === 'mese') return m;
        if (gran === 'trimestre') return 'Q' + Math.ceil((d.getMonth() + 1) / 3);
        if (gran === 'semestre') return 'S' + Math.ceil((d.getMonth() + 1) / 6);
        if (gran === 'settimana') {
            const firstDayOfYear = new Date(d.getFullYear(), 0, 1);
            const pastDaysOfYear = (d - firstDayOfYear) / 86400000;
            const w = Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
            return 'W' + ('0' + w).slice(-2);
        }
        if (gran === 'giorno') return m + '-' + ('0' + d.getDate()).slice(-2);
        if (gran === 'anno') return 'TOT';
        return '';
    }
formatDisplayLabel function · javascript · L2062-L2086 (25 LOC)
gb2/js/gb2-progressivi.js
    function formatDisplayLabel(key, gran, isYoY) {
        if (isYoY) {
            if (gran === 'anno' && key === 'TOT') return 'TOTALE ANNUO';
            if (gran === 'mese') {
                const mesi = ['GEN', 'FEB', 'MAR', 'APR', 'MAG', 'GIU', 'LUG', 'AGO', 'SET', 'OTT', 'NOV', 'DIC'];
                const idx = parseInt(key.split('-').pop(), 10) - 1;
                return mesi[idx >= 0 && idx < 12 ? idx : 0] || key;
            }
            if (gran === 'settimana' && key.startsWith('W')) return key;
            if (gran === 'giorno' && key.includes('-')) {
                const p = key.split('-');
                return `${p[1]}/${p[0]}`;
            }
            if (gran === 'trimestre' || gran === 'semestre') return key;
        }
        if (gran === 'anno') return key;
        if (gran === 'semestre' || gran === 'trimestre') return key.includes('-') ? key.split('-').reverse().join(' ') : key;
        if (gran === 'mese') {
            const mesi = ['GEN', 'FEB', 'MAR
popolaSidebarAnni function · javascript · L2088-L2160 (73 LOC)
gb2/js/gb2-progressivi.js
    function popolaSidebarAnni(anni) {
        const sidebar = document.getElementById('biSidebarAnni');
        if (!sidebar) return;

        sidebar.innerHTML = '<div style="font-size:0.7rem; font-weight:bold; color:var(--text-muted); text-align:center; margin-bottom:4px;">ANNI</div>';

        if (!biState.isYoY) {
            const btnAll = document.createElement('button');
            btnAll.className = 'mrp-nav-btn' + (!biState.filter ? ' active' : '');
            btnAll.style.width = '100%';
            btnAll.style.marginBottom = '6px';
            btnAll.style.padding = '4px';
            btnAll.textContent = 'Tutto';
            btnAll.onclick = () => {
                biState.filter = null;
                biState.granularity = 'anno';
                popolaSidebarAnni(anni);
                aggiornaGraficoBI();
            };
            sidebar.appendChild(btnAll);
        }

        let colorIdx = Object.keys(biState.yearColors).length;

        anni.sort().reverse().fo
aggiornaGraficoBI function · javascript · L2162-L2336 (175 LOC)
gb2/js/gb2-progressivi.js
    function aggiornaGraficoBI() {
        const rawData = consumiCache[currentCodartConsumi];
        if (!rawData) return;

        const labGran = document.getElementById('biGranularitaLabel');
        const breadcrumb = document.getElementById('biBreadcrumb');
        const canvas = document.getElementById('chartConsumi');
        if (labGran) labGran.textContent = biState.granularity.toUpperCase();
        if (breadcrumb) {
            breadcrumb.textContent = biState.isYoY ? 'Confronto Linee' : (biState.filter ? `Filtro: ${biState.filter}` : 'Tutto lo Storico');
        }
        syncBiGranularitaSelect();
        if (!canvas || typeof Chart === 'undefined') return;

        const anniSet = new Set();
        (rawData.past || []).concat(rawData.future || []).forEach((r) => {
            if (r.DataMov && String(r.DataMov).length >= 4) anniSet.add(String(r.DataMov).slice(0, 4));
        });

        const gran = biState.granularity;
        const mapData = {};
        const yoyMap 
apriModaleConsumi function · javascript · L2338-L2509 (172 LOC)
gb2/js/gb2-progressivi.js
    async function apriModaleConsumi(codart, descr) {
        const overlay = document.getElementById('modalConsumiOverlay');
        const titolo = document.getElementById('modalConsumiTitolo');
        const loading = document.getElementById('modalConsumiLoading');
        const content = document.getElementById('modalConsumiContent');
        const errorDiv = document.getElementById('modalConsumiError');
        const toolbar = document.getElementById('toolbarConsumi');
        const syncStatus = document.getElementById('biSyncStatus');
        const sidebar = document.getElementById('biSidebarAnni');
        const yoy = document.getElementById('biConfrontoYoY');
        const canvas = document.getElementById('chartConsumi');

        if (!overlay || !titolo || !loading || !content) return;

        if (errorDiv) {
            errorDiv.style.display = 'none';
            errorDiv.textContent = '';
        }
        loading.textContent = 'Caricamento dati di consumo...';

        con
apriModaleOrdiniRmp function · javascript · L2511-L2525 (15 LOC)
gb2/js/gb2-progressivi.js
    async function apriModaleOrdiniRmp(codart, fase) {
        const overlay = document.getElementById('modalOrdiniOverlay');
        const btnBack = document.getElementById('modalOrdiniBtnBack');
        const filtroLabel = document.getElementById('modalFiltroMagLabel');

        currentModalContext = { type: 'rmp', codart, fase };
        if (btnBack) btnBack.style.display = 'none';
        if (filtroLabel) filtroLabel.style.display = 'none';
        setActiveTab('modalTabRmp');

        if (!overlay) return;
        overlay.classList.add('open');

        await caricaRmpModale(codart, fase != null ? String(fase) : '');
    }
navigaProgressiviDaRmp function · javascript · L2527-L2544 (18 LOC)
gb2/js/gb2-progressivi.js
    async function navigaProgressiviDaRmp(codartTarget) {
        chiudiModale();
        const inputCodart = document.getElementById('inputCodart');
        if (inputCodart) inputCodart.value = codartTarget;
        try {
            const params = new URLSearchParams({ codart: codartTarget, magaz: '', fase: '', modo: '2', sintetico: '0' });
            const res = await fetch(`${MrpApp.API_BASE}/progressivi?${params}`, { credentials: 'include' });
            const data = await res.json();
            if (res.ok) {
                MrpApp.state.parametri = { codart: codartTarget, magaz: '', fase: '', modo: '2', sintetico: '0' };
                MrpApp.state.ultimoRisultato = data;
                render(data);
                MrpApp.switchView('progressivi');
            }
        } catch (err) {
            console.error('[RMP] Errore navigazione progressivi:', err);
        }
    }
Repobility — same analyzer, your code, free for public repos · /scan/
nestedDispSummary function · javascript · L2546-L2556 (11 LOC)
gb2/js/gb2-progressivi.js
    function nestedDispSummary(nestedTr) {
        const totals = nestedTr.querySelectorAll('tr.mrp-row-totale[data-disp-netta], tr.mrp-row-totale-cross[data-disp-netta]');
        const parts = [];
        totals.forEach(t => {
            const v = t.getAttribute('data-disp-netta');
            const fase = t.querySelector('td:nth-child(2)');
            const fz = fase ? fase.textContent.trim() : '';
            if (v != null && v !== '') parts.push(`Fase ${fz || '?'}: Disp.netta=${fmt(Number(v))}`);
        });
        return parts.length ? parts.join('; ') : '';
    }
exportTreeToClipboard function · javascript · L2558-L2609 (52 LOC)
gb2/js/gb2-progressivi.js
    function exportTreeToClipboard() {
        const rows = document.querySelectorAll('#tblProgressivi tr.mrp-row-articolo, #tblProgressivi tr.row-magazzino, #tblProgressivi tr.mrp-row-totale, #tblProgressivi tr.mrp-row-totale-cross, #tblProgressivi tr.mrp-row-generale-totale');
        const showScaduti = document.body.classList.contains('show-scaduti');
        let output = "ESTRAZIONE ALBERO MRP\n=====================\n";

        const ths = document.querySelectorAll('#tblProgressivi thead th');
        const headers = [];
        ths.forEach(th => headers.push(th.innerText.replace(/\s+/g, ' ').trim()));
        if (headers.length > 0) {
            output += 'COLONNE: ' + headers.join(' | ') + "\n---------------------\n";
        }

        rows.forEach((row) => {
            if (!showScaduti && row.classList.contains('row-scaduto')) return;
            if (row.style.display === 'none') return;

            const livello = parseInt(row.getAttribute('data-livello') || '0', 10);
   
fmt function · javascript · L2611-L2616 (6 LOC)
gb2/js/gb2-progressivi.js
    function fmt(n) {
        if (n === '' || n === null || n === undefined) return '';
        const num = Number(n);
        if (isNaN(num)) return '';
        return num === 0 ? '0' : num.toLocaleString('it-IT');
    }
fmtDate function · javascript · L2618-L2623 (6 LOC)
gb2/js/gb2-progressivi.js
    function fmtDate(d) {
        if (!d) return '';
        const dt = (d instanceof Date) ? d : new Date(d);
        if (isNaN(dt.getTime())) return '';
        return dt.toLocaleDateString('it-IT', { day: '2-digit', month: '2-digit', year: 'numeric' });
    }
esc function · javascript · L2625-L2628 (4 LOC)
gb2/js/gb2-progressivi.js
    function esc(s) {
        if (s === null || s === undefined) return '';
        return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
    }
waitForDB function · javascript · L7-L16 (10 LOC)
gb2/js/gb2-proposta.js
    async function waitForDB(maxRetries = 5) {
        for (let i = 0; i < maxRetries; i++) {
            try {
                const res = await fetch(`${MrpApp.API_BASE}/health`, { credentials: 'include' });
                const dataHealth = await res.json();
                if (dataHealth.status === 'ok') return;
            } catch (e) { /* ignore */ }
            await new Promise(r => setTimeout(r, 1000));
        }
    }
init function · javascript · L18-L33 (16 LOC)
gb2/js/gb2-proposta.js
    async function init() {
        const btnRefresh = document.getElementById('btnRefreshProposta');
        if (btnRefresh) btnRefresh.addEventListener('click', caricaProposta);

        const body = document.getElementById('propostaBody');
        if (body) body.addEventListener('click', onPropostaBodyClick);

        // Delegation per pulsanti modifica/rimuovi conferma nei badge articolo
        const listEl = document.getElementById('propostaList');
        if (listEl) {
            listEl.addEventListener('click', onPropostaListBadgeClick);
        }

        await waitForDB();
        caricaProposta();
    }
onPropostaListBadgeClick function · javascript · L35-L87 (53 LOC)
gb2/js/gb2-proposta.js
    function onPropostaListBadgeClick(e) {
        const btnModifica = e.target.closest('.btn-modifica-conferma');
        const btnRimuovi = e.target.closest('.btn-rimuovi-conferma');

        if (btnModifica) {
            e.stopPropagation();
            const key = btnModifica.dataset.key;
            const ordine = MrpApp.state.ordiniConfermati.get(key);
            if (!ordine) return;

            MrpApp.state.propostaCorrente = {
                fornitore_codice: ordine.fornitore_codice,
                fornitore_nome: ordine.fornitore_nome,
                ol_codart: ordine.ol_codart,
                ar_codalt: ordine.ar_codalt,
                ar_descr: ordine.ar_descr,
                ol_fase: ordine.ol_fase,
                ol_magaz: ordine.ol_magaz,
                ol_unmis: ordine.ol_unmis,
                ol_progr: ordine.ol_progr || 0,
                ol_quant: ordine.quantita_proposta,
                ol_prezzo: ordine.prezzo,
                ol_datcons: ordine.data_co
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
onPropostaBodyClick function · javascript · L89-L165 (77 LOC)
gb2/js/gb2-proposta.js
    async function onPropostaBodyClick(e) {
        const header = e.target.closest('.proposta-fornitore-header');
        if (header) {
            const bodyEl = header.nextElementSibling;
            const toggle = header.querySelector('.forn-toggle');
            if (bodyEl && bodyEl.classList.contains('proposta-fornitore-body')) {
                if (bodyEl.style.display === 'none') {
                    bodyEl.style.display = 'block';
                    if (toggle) toggle.textContent = '▼';
                } else {
                    bodyEl.style.display = 'none';
                    if (toggle) toggle.textContent = '▶';
                }
            }
            return;
        }

        const codartEl = e.target.closest('.proposta-art-codart');
        if (!codartEl) return;

        // Pulsanti modifica/rimuovi conferma gestiti da delegation più in basso
        if (e.target.closest('.btn-modifica-conferma') || e.target.closest('.btn-rimuovi-conferma')) return;

        co
caricaProposta function · javascript · L167-L207 (41 LOC)
gb2/js/gb2-proposta.js
    async function caricaProposta() {
        const listEl = document.getElementById('propostaList');
        const loading = document.getElementById('propostaLoading');
        const stats = document.getElementById('propostaStats');

        if (!listEl) return;

        if (loading) loading.style.display = 'block';
        listEl.innerHTML = '';
        if (stats) stats.innerHTML = '';

        try {
            const res = await fetch(`${MrpApp.API_BASE}/proposta-ordini`, { credentials: 'include' });
            const payload = await res.json();

            if (loading) loading.style.display = 'none';

            if (!res.ok) {
                const msg = payload && payload.error ? payload.error : 'Sconosciuto';
                listEl.innerHTML = `<div class="proposta-loading" style="color:var(--danger)">Errore: ${esc(String(msg))}</div>`;
                return;
            }

            if (!Array.isArray(payload) || !payload.length) {
                listEl.innerHTML = '<div c
renderProposta function · javascript · L209-L384 (176 LOC)
gb2/js/gb2-proposta.js
    function renderProposta(righe, listEl, statsEl) {
        const fornitori = new Map();

        for (const r of righe) {
            const fk = String(r.fornitore_codice);
            if (!fornitori.has(fk)) {
                fornitori.set(fk, {
                    codice: fk,
                    nome: r.fornitore_nome || '',
                    articoli: new Map()
                });
            }
            const forn = fornitori.get(fk);
            const ak = r.ol_codart;
            if (!forn.articoli.has(ak)) {
                forn.articoli.set(ak, []);
            }
            forn.articoli.get(ak).push(r);
        }

        let totaleValore = 0;
        let totArticoli = 0;
        fornitori.forEach(f => {
            totArticoli += f.articoli.size;
            f.articoli.forEach(rows => {
                rows.forEach(r => {
                    totaleValore += (Number(r.ol_quant) || 0) * (Number(r.ol_prezzo) || 0);
                });
            });
        });

       
fmtNum function · javascript · L386-L394 (9 LOC)
gb2/js/gb2-proposta.js
    function fmtNum(n, decimals) {
        if (n === null || n === undefined) return '';
        const num = Number(n);
        if (Number.isNaN(num)) return '';
        return num.toLocaleString('it-IT', {
            minimumFractionDigits: decimals || 0,
            maximumFractionDigits: decimals || 0
        });
    }
fmtDate function · javascript · L396-L401 (6 LOC)
gb2/js/gb2-proposta.js
    function fmtDate(d) {
        if (!d) return '';
        const dt = new Date(d);
        if (Number.isNaN(dt.getTime())) return '';
        return dt.toLocaleDateString('it-IT', { day: '2-digit', month: '2-digit', year: 'numeric' });
    }
esc function · javascript · L403-L410 (8 LOC)
gb2/js/gb2-proposta.js
    function esc(s) {
        if (s === null || s === undefined) return '';
        return String(s)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;');
    }
escAttr function · javascript · L412-L419 (8 LOC)
gb2/js/gb2-proposta.js
    function escAttr(s) {
        if (s === null || s === undefined) return '';
        return String(s)
            .replace(/&/g, '&amp;')
            .replace(/"/g, '&quot;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
    }
aggiornaStatoVisivo function · javascript · L421-L467 (47 LOC)
gb2/js/gb2-proposta.js
    function aggiornaStatoVisivo() {
        const confermati = MrpApp.state.ordiniConfermati;

        document.querySelectorAll('.proposta-articolo').forEach(artEl => {
            const codartEl = artEl.querySelector('.proposta-art-codart');
            if (!codartEl) return;

            const key = MrpApp.getKeyOrdine(
                codartEl.dataset.fornitore,
                codartEl.dataset.codart,
                codartEl.dataset.fase || '0',
                codartEl.dataset.magaz || '1'
            );
            const ordine = confermati.get(key);

            artEl.classList.remove('proposta-art-confermato', 'proposta-art-escluso');
            const oldBadge = artEl.querySelector('.proposta-conferma-badge');
            if (oldBadge) oldBadge.remove();

            if (ordine) {
                const badge = document.createElement('div');
                badge.className = 'proposta-conferma-badge';
                if (ordine.escluso) {
                    artEl.classList.
Open data scored by Repobility · https://repobility.com
aggiornaBarreFornitori function · javascript · L469-L573 (105 LOC)
gb2/js/gb2-proposta.js
    function aggiornaBarreFornitori() {
        const confermati = MrpApp.state.ordiniConfermati;

        document.querySelectorAll('.proposta-fornitore').forEach(fornEl => {
            const header = fornEl.querySelector('.proposta-fornitore-header');
            const articoli = fornEl.querySelectorAll('.proposta-articolo');
            if (!header || articoli.length === 0) return;

            const fornCode = header.dataset.forn;
            let tuttiGestiti = true;
            let conteggioConfermati = 0;
            let conteggioEsclusi = 0;
            let totaleValore = 0;

            articoli.forEach(artEl => {
                const codartEl = artEl.querySelector('.proposta-art-codart');
                if (!codartEl) { tuttiGestiti = false; return; }
                const key = MrpApp.getKeyOrdine(
                    codartEl.dataset.fornitore,
                    codartEl.dataset.codart,
                    codartEl.dataset.fase || '0',
                    codartEl.datas
ripristinaOrdiniEmessiDaServer function · javascript · L589-L618 (30 LOC)
gb2/js/gb2-proposta.js
    function ripristinaOrdiniEmessiDaServer(righe) {
        // Svuota la Map — verrà ripopolata interamente dal server
        ordiniEmessi.clear();

        // Raggruppa righe per fornitore
        const fornitori = new Map();
        for (const r of righe) {
            const fk = String(r.fornitore_codice);
            if (!fornitori.has(fk)) fornitori.set(fk, { righe: [], nome: r.fornitore_nome || '' });
            fornitori.get(fk).righe.push(r);
        }

        for (const [fk, info] of fornitori) {
            const tutteEmesse = info.righe.every(r => r.emesso === true);
            if (tutteEmesse && info.righe.length > 0) {
                const primo = info.righe[0];
                const cached = pdfCache.get(fk) || {};
                ordiniEmessi.set(fk, {
                    anno: primo.ord_anno,
                    serie: primo.ord_serie,
                    numord: primo.ord_numord,
                    pdf_base64: cached.pdf_base64 || null,
                    pdf_f
aggiornaBarraEmettiTutti function · javascript · L623-L660 (38 LOC)
gb2/js/gb2-proposta.js
    function aggiornaBarraEmettiTutti() {
        const listEl = document.getElementById('propostaList');
        if (!listEl) return;

        let barraEl = document.getElementById('barraEmettiTutti');
        const completati = document.querySelectorAll('.proposta-fornitore-header.fornitore-completato');

        // Conta fornitori pronti (completati e non ancora emessi)
        let fornitoriPronti = 0;
        completati.forEach(h => {
            const fc = h.dataset.forn;
            if (!ordiniEmessi.has(fc)) fornitoriPronti++;
        });

        if (fornitoriPronti === 0) {
            if (barraEl) barraEl.style.display = 'none';
            return;
        }

        if (!barraEl) {
            barraEl = document.createElement('div');
            barraEl.id = 'barraEmettiTutti';
            barraEl.className = 'proposta-emetti-tutti-bar';
            listEl.parentNode.insertBefore(barraEl, listEl);
        }

        barraEl.style.display = 'flex';
        barraEl.innerHTML =
modale function · javascript · L665-L700 (36 LOC)
gb2/js/gb2-proposta.js
    function modale(tipo, titolo, messaggio, pulsanti) {
        return new Promise(resolve => {
            const overlay = document.getElementById('modalGenericOverlay');
            const titoloEl = document.getElementById('modalGenericTitolo');
            const iconaEl = document.getElementById('modalGenericIcona');
            const msgEl = document.getElementById('modalGenericMessaggio');
            const azioniEl = document.getElementById('modalGenericAzioni');

            titoloEl.textContent = titolo;
            msgEl.innerHTML = messaggio;

            const icone = { success: '\u2705', error: '\u274C', warning: '\u26A0\uFE0F', info: '\u2139\uFE0F', question: '\u2753' };
            iconaEl.textContent = icone[tipo] || '';

            azioniEl.innerHTML = '';
            (pulsanti || [{ label: 'OK', value: true, style: 'primary' }]).forEach(btn => {
                const b = document.createElement('button');
                b.className = 'modal-generic-btn modal-generic-
chiamaConAutoDeploySP function · javascript · L705-L740 (36 LOC)
gb2/js/gb2-proposta.js
    async function chiamaConAutoDeploySP(url, body) {
        let resp = await fetch(url, { credentials: 'include',
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(body)
        });
        let data = await resp.json();

        if (data.error === 'SP_NOT_FOUND') {
            const ok = await modale('warning',
                'Stored Procedure Mancante',
                `La stored procedure <strong>${esc(data.sp)}</strong> non esiste nel database MRP corrente.<br><br>Vuoi crearla automaticamente?`,
                [
                    { label: 'Crea e Riprova', value: true, style: 'success' },
                    { label: 'Annulla', value: false, style: 'secondary' }
                ]
            );
            if (ok) {
                const deployResp = await fetch(`${MrpApp.API_BASE}/deploy-sp`, { credentials: 'include', method: 'POST' });
                const deployData = await deployResp.json();
         
assicuraSPEsiste function · javascript · L745-L778 (34 LOC)
gb2/js/gb2-proposta.js
    async function assicuraSPEsiste() {
        try {
            const resp = await fetch(`${MrpApp.API_BASE}/check-sp`, { credentials: 'include' });
            const data = await resp.json();
            if (data.exists) return true;
        } catch (_) {
            // se il check fallisce, proviamo comunque a deployare
        }

        const ok = await modale('warning', 'Configurazione Database',
            'La stored procedure necessaria non è ancora presente nel database MRP.<br><br>' +
            'Verrà installata automaticamente (operazione da eseguire una sola volta).',
            [
                { label: 'Installa e Continua', value: true, style: 'success' },
                { label: 'Annulla', value: false, style: 'secondary' }
            ]);

        if (!ok) return false;

        try {
            const deployResp = await fetch(`${MrpApp.API_BASE}/deploy-sp`, { credentials: 'include', method: 'POST' });
            const deployData = await deployResp.json();
    
apriModaleEmettiOrdine function · javascript · L783-L832 (50 LOC)
gb2/js/gb2-proposta.js
    async function apriModaleEmettiOrdine(fornitore_codice) {
        if (!await assicuraSPEsiste()) return;
        const confermati = MrpApp.state.ordiniConfermati;
        const articoliFornitore = [];
        let fornitore_nome = '';

        confermati.forEach((ordine, key) => {
            if (String(ordine.fornitore_codice) === String(fornitore_codice) && !ordine.escluso) {
                articoliFornitore.push(ordine);
                if (!fornitore_nome) fornitore_nome = ordine.fornitore_nome || '';
            }
        });

        if (articoliFornitore.length === 0) return;

        const totale = articoliFornitore.reduce((s, a) => s + a.quantita_confermata * a.prezzo, 0);

        const riepilogoEl = document.getElementById('emettiRiepilogo');
        riepilogoEl.innerHTML = `
            <div class="emetti-riepilogo-fornitore">${esc(fornitore_nome)} (${esc(String(fornitore_codice))})</div>
            <table class="emetti-riepilogo-table">
                <thead><tr><th>
eseguiEmissioneOrdine function · javascript · L837-L869 (33 LOC)
gb2/js/gb2-proposta.js
    async function eseguiEmissioneOrdine(fornitore_codice, articoliFornitore, fornitore_nome) {
        const body = {
            fornitore_codice: parseInt(fornitore_codice, 10),
            elaborazione_id: MrpApp.state.elaborazioneId || '',
            articoli: articoliFornitore.map(a => ({
                codart: a.ol_codart,
                fase: parseInt(a.ol_fase, 10) || 0,
                magaz: parseInt(a.ol_magaz, 10) || 1,
                quantita: a.quantita_confermata,
                data_consegna: a.data_consegna,
                prezzo: a.prezzo,
                unmis: a.ol_unmis || 'PZ',
                ol_progr: parseInt(a.ol_progr, 10) || 0
            }))
        };

        const data = await chiamaConAutoDeploySP(`${MrpApp.API_BASE}/emetti-ordine`, body);

        if (data.success) {
            // Salva PDF in memoria per download immediato (non disponibile dal server dopo)
            pdfCache.set(String(fornitore_codice), {
                pdf_base64: data.pd
All rows scored by the Repobility analyzer (https://repobility.com)
mostraRisultatoEmissione function · javascript · L874-L934 (61 LOC)
gb2/js/gb2-proposta.js
    function mostraRisultatoEmissione(data, fornitore_nome) {
        const overlay = document.getElementById('modalRisultatoOverlay');
        const contenuto = document.getElementById('risultatoContenuto');
        const azioni = document.getElementById('risultatoAzioni');

        contenuto.innerHTML = `
            <div class="risultato-ok-icon">\u2705</div>
            <div class="risultato-ordine-num">Ordine n. ${data.ordine.numord}/${data.ordine.serie}</div>
            <div class="risultato-ordine-forn">${esc(fornitore_nome)}</div>
            <div style="text-align:center; font-size:0.85rem; color:var(--text-muted);">
                ${data.ordine.num_righe} articol${data.ordine.num_righe > 1 ? 'i' : 'o'} &mdash;
                Totale \u20ac ${Number(data.ordine.totale_documento || 0).toLocaleString('it-IT', { minimumFractionDigits: 2 })}
            </div>
        `;

        azioni.innerHTML = '';

        // Pulsante scarica PDF
        const btnPdf = document.createElemen
scaricaPdfBase64 function · javascript · L939-L949 (11 LOC)
gb2/js/gb2-proposta.js
    function scaricaPdfBase64(base64, filename) {
        const blob = new Blob([Uint8Array.from(atob(base64), c => c.charCodeAt(0))], { type: 'application/pdf' });
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = filename || 'ordine.pdf';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(url);
    }
scaricaPdf function · javascript · L951-L957 (7 LOC)
gb2/js/gb2-proposta.js
    function scaricaPdf(emesso) {
        if (emesso.pdf_base64) {
            scaricaPdfBase64(emesso.pdf_base64, emesso.pdf_filename);
        } else {
            window.open(`${MrpApp.API_BASE}/ordine-pdf/${emesso.anno}/${emesso.serie}/${emesso.numord}`, '_blank');
        }
    }
inviaEmailOrdine function · javascript · L962-L1031 (70 LOC)
gb2/js/gb2-proposta.js
    async function inviaEmailOrdine(emesso) {
        const body = {
            anno: emesso.anno,
            serie: emesso.serie,
            numord: emesso.numord,
            pdf_base64: emesso.pdf_base64 || null,
            pdf_filename: emesso.pdf_filename || null
        };

        try {
            const resp = await fetch(`${MrpApp.API_BASE}/invia-ordine-email`, { credentials: 'include',
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify(body)
            });
            const data = await resp.json();

            if (data.error === 'SMTP_NOT_CONFIGURED') {
                await modale('warning', 'SMTP Non Configurato',
                    'Per inviare email \u00e8 necessario configurare un profilo SMTP nelle impostazioni.',
                    [{ label: 'OK', value: true, style: 'primary' }]);
                return;
            }

            if (data.error === 'EMAIL_MISSING') {
         
emettiTuttiHandler function · javascript · L1036-L1139 (104 LOC)
gb2/js/gb2-proposta.js
    async function emettiTuttiHandler() {
        if (!await assicuraSPEsiste()) return;

        const completati = document.querySelectorAll('.proposta-fornitore-header.fornitore-completato');
        const fornitori = [];

        completati.forEach(h => {
            const fc = h.dataset.forn;
            if (ordiniEmessi.has(fc)) return; // gia emesso
            const articoliFornitore = [];
            const confermati = MrpApp.state.ordiniConfermati;
            confermati.forEach((ordine, key) => {
                if (String(ordine.fornitore_codice) === String(fc) && !ordine.escluso) {
                    articoliFornitore.push(ordine);
                }
            });
            if (articoliFornitore.length > 0) {
                fornitori.push({ fornitore_codice: fc, articoli: articoliFornitore, nome: articoliFornitore[0].fornitore_nome || fc });
            }
        });

        if (fornitori.length === 0) return;

        const conferma = await modale('question', 'Confe
init function · javascript · L165-L190 (26 LOC)
gb2/js/gb2-theme.js
    function init() {
        // 1. Carica da localStorage (sincrono)
        const cached = localStorage.getItem('mrp-theme');
        if (cached) {
            try {
                const data = JSON.parse(cached);
                currentPreset = data.colorPreset || 'default';
                customColors = data.customColors || {};
                customLabels = data.customLabels || {};
                applyPresetInternal(currentPreset, customColors);
            } catch (e) {
                console.warn('[MrpTheme] Cache locale corrotta, uso default');
            }
        }

        // 2. Fetch preferenze server in background
        fetchServerPreferences();

        // 3. Listener globali
        document.addEventListener('keydown', onKeyDown);
        document.body.addEventListener('click', onBodyClick);

        // 4. Bottone apertura pannello
        const btnOpen = document.getElementById('btnOpenTheme');
        if (btnOpen) btnOpen.addEventListener('click', openPanel);
  
fetchServerPreferences function · javascript · L192-L219 (28 LOC)
gb2/js/gb2-theme.js
    function fetchServerPreferences() {
        const base = (typeof MrpApp !== 'undefined' && MrpApp.API_BASE) ? MrpApp.API_BASE : '/api/mrp';
        fetch(base + '/user/preferences', { credentials: 'include' })
            .then(res => {
                if (!res.ok) throw new Error('HTTP ' + res.status);
                return res.json();
            })
            .then(data => {
                if (!data) return;
                const serverPreset = data.colorPreset || 'default';
                const serverColors = data.customColors || {};
                const serverLabels = data.customLabels || {};

                // Confronta con cache: se diverso, aggiorna
                const cacheStr = JSON.stringify({ colorPreset: currentPreset, customColors, customLabels });
                const serverStr = JSON.stringify({ colorPreset: serverPreset, customColors: serverColors, customLabels: serverLabels });
                if (cacheStr !== serverStr) {
                    currentPrese
applyColors function · javascript · L225-L234 (10 LOC)
gb2/js/gb2-theme.js
    function applyColors(colors) {
        const root = document.documentElement;
        Object.keys(colors).forEach(key => {
            if (colors[key]) {
                root.style.setProperty(key, colors[key]);
            } else {
                root.style.removeProperty(key);
            }
        });
    }
Repobility — same analyzer, your code, free for public repos · /scan/
removeAllOverrides function · javascript · L236-L241 (6 LOC)
gb2/js/gb2-theme.js
    function removeAllOverrides() {
        const root = document.documentElement;
        COLOR_GROUPS.forEach(g => g.vars.forEach(v => {
            root.style.removeProperty(v.name);
        }));
    }
applyPreset function · javascript · L247-L263 (17 LOC)
gb2/js/gb2-theme.js
    function applyPreset(presetName) {
        if (presetName === 'custom') {
            document.documentElement.removeAttribute('data-theme');
            removeAllOverrides();
            applyColors(customColors);
        } else if (presetName === 'default') {
            document.documentElement.removeAttribute('data-theme');
            removeAllOverrides();
        } else if (PRESETS[presetName]) {
            document.documentElement.dataset.theme = presetName;
            removeAllOverrides();
            applyColors(PRESETS[presetName]);
        }
        currentPreset = presetName;
        updateLocalStorage();
        updatePanelPresetDropdown();
    }
applyPresetInternal function · javascript · L266-L284 (19 LOC)
gb2/js/gb2-theme.js
    function applyPresetInternal(presetName, colors) {
        if (presetName === 'custom') {
            document.documentElement.removeAttribute('data-theme');
            removeAllOverrides();
            applyColors(colors || {});
        } else if (presetName === 'default') {
            document.documentElement.removeAttribute('data-theme');
            removeAllOverrides();
        } else if (PRESETS[presetName]) {
            document.documentElement.dataset.theme = presetName;
            removeAllOverrides();
            applyColors(PRESETS[presetName]);
            // Applica anche eventuali custom su preset
            if (colors && Object.keys(colors).length) {
                applyColors(colors);
            }
        }
        currentPreset = presetName;
    }
‹ prevpage 4 / 6next ›