1/** 2 * tec-appalti-art26-autofill.js â Compila gap Tab 15 Ditte Esterne (ITP, info rischi, DUVRI) 3 * @version 20.124.50 4 */ 5(function (g) { 6 'use strict'; 7 8 /** 9 * ââ v20.373.125 â UN CATALOGO DI UN CLIENTE SOLO NON STA NEL PRODOTTO ââââââââââââââââââââââââ 10 * Qui viveva WLAKE_SPORT_APPALTI: cinque ditte con ragione sociale, partita IVA e nome del 11 * datore di lavoro di UN cliente specifico, dentro il codice che gira per tutti. Violava la 12 * regola d'oro del progetto â «nessun criterio puo' valere per un cliente solo» â e non aveva 13 * alcun chiamante nel prodotto: la usava soltanto un banco di prova. 14 * Il dato di prova appartiene al banco, non all'applicazione: e' stato spostato in 15 * tools/lib/wlake-dummy-fixture.js, dove sta il resto di quel cliente finto. 16 * L'autofill generico (autofillAppaltiArt26) resta: quello lavora su qualunque cliente. 17 */ 18 19 function hasIdentity(a) { 20 return !!(a && ((a.ditta && String(a.ditta).trim()) || a.ragioneSocialeTBD === 'si')); 21 } 22 23 function itpStato(a) { 24 if (!a || !a.verificaITP) return 'mancante'; 25 if (a.verificaITP === 'si' || a.verificaITP === true) return 'ok'; 26 if (a.verificaITP === 'no' || a.verificaITP === false) return 'no'; 27 return 'ok'; 28 } 29 30 function duvriStato(a) { 31 var intf = a.interferenze || 'no'; 32 if (intf === 'no') return a.duvri ? 'ok' : 'ok'; 33 if (a.duvri === 'no') return 'no'; 34 if (!a.duvri) return 'mancante'; 35 return 'ok'; 36 } 37 38 function appaltoGapList(a) { 39 if (!hasIdentity(a)) return ['identita']; 40 var gaps = []; 41 var itp = itpStato(a); 42 if (itp === 'no' || itp === 'mancante') gaps.push('verificaITP'); 43 if (!a.infoRischi || a.infoRischi === 'no') gaps.push('infoRischi'); 44 if (!a.cooperazione || a.cooperazione === 'no') gaps.push('cooperazione'); 45 if (!a.ddlDitta || !String(a.ddlDitta).trim()) gaps.push('ddlDitta'); 46 var ds = duvriStato(a); 47 if (ds === 'no' || ds === 'mancante') gaps.push('duvri'); 48 if (!a.piva || !String(a.piva).trim()) gaps.push('piva'); 49 if (!a.nAddetti) gaps.push('nAddetti'); 50 return gaps; 51 } 52 53 function appaltoCompleto(a) { 54 return appaltoGapList(a).length === 0; 55 } 56 57 function listAppaltiMancanti(d) { 58 d = d || {}; 59 var ap = d.appalti || []; 60 var out = []; 61 ap.forEach(function (a, idx) { 62 var gaps = appaltoGapList(a); 63 if (!gaps.length) return; 64 var label = (a.ditta || a.tipo || ('Appalto ' + (idx + 1))).slice(0, 48); 65 out.push({ idx: idx, label: label, gaps: gaps, orfana: gaps.indexOf('identita') >= 0 }); 66 }); 67 return out; 68 } 69 70 function deriveTipologia(a, d) { 71 if (g._tecDuvriHub && typeof g._tecDuvriHub.deriveTipologiaAppalto === 'function') { 72 return g._tecDuvriHub.deriveTipologiaAppalto(a, d) || ''; 73 } 74 return a.tipologiaAppalto || ''; 75 } 76 77 function inferInterferenze(a, d) { 78 if (a.interferenze && a.interferenze !== 'no') return a.interferenze; 79 if (g._tecDuvriHub && g._tecDuvriHub.buildPropostaInterferenze) { 80 try { 81 var p = g._tecDuvriHub.buildPropostaInterferenze(a, d); 82 if (p && p.interferenze) return p.interferenze; 83 } catch (_) { /* optional */ } 84 } 85 var cat = deriveTipologia(a, d); 86 if (cat === 'sport_wakeboard' || cat === 'edile' || cat === 'manutenzione') return 'si_medie'; 87 if (cat === 'pulizie' || cat === 'catering') return 'si_basse'; 88 return 'no'; 89 } 90 91 function defaultDuvri(a) { 92 var intf = a.interferenze || 'no'; 93 if (intf === 'no') return 'non_necessario'; 94 return 'integrato'; 95 } 96 97 function patchAppalto(a, d, opts) { 98 opts = opts || {}; 99 if (!a || a.overriddenByTecnico) return {}; 100 var patch = {}; 101 var cat = deriveTipologia(a, d); 102 if (!a.tipologiaAppalto && cat) patch.tipologiaAppalto = cat; 103 if (!a.interferenze) patch.interferenze = inferInterferenze(a, d); 104 var merged = Object.assign({}, a, patch); 105 106 if (hasIdentity(a)) { 107 if (!a.verificaITP) patch.verificaITP = 'si'; 108 if (!a.infoRischi || a.infoRischi === 'no') patch.infoRischi = 'si'; 109 if (!a.cooperazione || a.cooperazione === 'no') patch.cooperazione = 'si'; 110 if (!a.ddlDitta && a.referente) patch.ddlDitta = a.referente;
111 if (!merged.duvri || merged.duvri === 'no') patch.duvri = defaultDuvri(merged); 112 if (!a.misureCoordinamento && merged.interferenze && merged.interferenze !== 'no') { 113 patch.misureCoordinamento = 'Briefing RSPP; delimitazione aree; orari coordinati (art. 26 c.2)'; 114 } 115 if (g._tecDuvriHub && typeof g._tecDuvriHub.buildPropostaInterferenze === 'function' && !a.propostaInterferenzeMeta) { 116 try { patch.propostaInterferenzeMeta = g._tecDuvriHub.buildPropostaInterferenze(Object.assign({}, a, patch), d); } catch (_) { /* optional */ } 117 } 118 } 119 return patch; 120 } 121 122 function autofillAppaltiArt26(d, opts) { 123 opts = opts || {}; 124 if (!d) return { filled: 0, missing: [] }; 125 if (!Array.isArray(d.appalti)) d.appalti = []; 126 var filled = 0; 127 d.appalti.forEach(function (a) { 128 if (!a) return; 129 var before = appaltoGapList(a).join(','); 130 var patch = patchAppalto(a, d, opts); 131 var keys = Object.keys(patch); 132 if (!keys.length) return; 133 keys.forEach(function (k) { a[k] = patch[k]; }); 134 a.fonteAutofill = true; 135 var after = appaltoGapList(a).join(','); 136 if (before !== after) filled++; 137 }); 138 return { filled: filled, missing: listAppaltiMancanti(d) }; 139 } 140 141 function countItpGap(d) { 142 return (d.appalti || []).filter(function (a) { 143 return hasIdentity(a) && (itpStato(a) === 'no' || itpStato(a) === 'mancante'); 144 }).length; 145 } 146 147 g._tecAppaltiArt26 = { 148 version: '20.124.50', 149 hasIdentity: hasIdentity, 150 itpStato: itpStato, 151 appaltoCompleto: appaltoCompleto, 152 listAppaltiMancanti: listAppaltiMancanti, 153 autofillAppaltiArt26: autofillAppaltiArt26, 154 countItpGap: countItpGap 155 }; 156 157 g._autofillAppaltiArt26Mancanti = function (opts) { 158 var d = (typeof D === 'function') ? D() : null; 159 if (!d) return { error: 'D() non disponibile' }; 160 var res = autofillAppaltiArt26(d, opts); 161 if (typeof setD === 'function') setD('appalti', d.appalti); 162 if (typeof renderTab === 'function') renderTab(); 163 if (g.toast && res.filled) g.toast('Tab 15: aggiornate ' + res.filled + ' ditte (ITP/Art. 26)', 'success'); 164 return res; 165 }; 166 167 if (g.console) g.console.log('[tec-appalti-art26-autofill] v20.124.50 â _autofillAppaltiArt26Mancanti()'); 168})(typeof window !== 'undefined' ? window : globalThis);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.