Outils de Collaboration
Connexion...
M
Tableau de bord
Toutes les tâches du chantier
Planning
Jalons et échéances
Artisans
Intervenants du chantier
Budget
Chargement...
Journal de chantier
Notes et observations
Checklist
Tâches administratives
Historique
30 dernières modifications
0 ? Math.min(100,Math.round(total/bt*100)) : 0; var stats = document.getElementById('bud-stats'); if(stats) { stats.innerHTML = [ {v:fmt(bt)+'€', l:'Budget total'}, {v:fmt(total)+'€', l:'Dépenses TTC'}, {v:fmt(total/1.2)+'€', l:'Total HT'}, {v:fmt(reste)+'€', l:'Restant'}, {v:pct+'%', l:'Engagé'} ].map(function(s){ return '
'+s.v+'
'+s.l+'
'; }).join(''); } var ps = document.getElementById('bud-ps'); if(ps) ps.textContent = DB.budget.length+' ligne'+(DB.budget.length>1?'s':''); if(!DB.budget.length) { el.innerHTML='
💶
' +'
Aucune dépense
' +'
Cliquez + ci-dessous pour ajouter une ligne
' +'
' +'+ Ajouter une ligne
'; return; } var allCols = getBCols(); var visCols = allCols.filter(function(c){ return c.vis; }); var h = '
'; visCols.forEach(function(col, ci) { var aci = allCols.indexOf(col); h += ''; }); h += ''; h += ''; DB.budget.forEach(function(b) { var rowBg = b.rowColor||'#fff'; h += ''; visCols.forEach(function(col) { var aci = allCols.indexOf(col); if(col.id==='color') { h += ''; } else if(col.type==='status') { var sv = b[col.id]||''; var sidx = (col.opts||[]).indexOf(sv); var sbg = (sidx>=0&&col.colors) ? col.colors[sidx] : '#c4c4c4'; h += ''; } else if(col.type==='vatcalc') { var tva = b.montantTVA!==undefined ? parseFloat(b.montantTVA)||0 : ((parseFloat(b.montant)||0)-(parseFloat(b.montant)||0)/1.2); h += ''; } else if(col.type==='htcalc') { var ht = b.montantHT!==undefined ? parseFloat(b.montantHT)||0 : (parseFloat(b.montant)||0)/1.2; h += ''; } else if(col.type==='number') { var nv = parseFloat(b[col.id])||0; h += ''; } else if(col.type==='date') { h += ''; } else if(col.type==='file') { var fv = b[col.id]||null; if(fv&&fv.name) { h += ''; } else { h += ''; } } else { // text (default) var tv = b[col.id]||''; h += ''; } }); h += '' +''; }); // Inline add row h += '' +''; // tfoot h += ''; visCols.forEach(function(col) { if(['number','vatcalc','htcalc'].indexOf(col.type) !== -1) { var tot, tcol='var(--text)'; if(col.type==='vatcalc') { tot=DB.budget.reduce(function(s,b){var m=parseFloat(b.montant)||0;return s+(m-m/1.2);},0); tcol='#d97706'; } else if(col.type==='htcalc') { tot=DB.budget.reduce(function(s,b){return s+(parseFloat(b.montant)||0)/1.2;},0); tcol='#676879'; } else { tot=DB.budget.reduce(function(s,b){return s+(parseFloat(b[col.id])||0);},0); if(col.id==='montant')tcol='#0073ea'; } h += ''; } else { h += ''; } }); h += '
'; if(!col.fixed) { h += ''+col.label+''; } h += '+
' +'
' +'' +'' +'
' +(sv?''+sv+'':'')+'' +''+(tva>0?fmt(tva.toFixed(2))+'€':'auto')+'' +''+(ht>0?fmt(ht.toFixed(2))+'€':'auto')+'' +''+(nv?fmt(nv.toFixed(2))+'€':'')+'' +'📎 '+fv.name+'' +'×' +'' +''+(tv||'')+'
' +'' +'+ Cliquer pour ajouter une ligne' +'' +'
'+fmt(tot.toFixed(2))+'€
'; el.innerHTML = h; // ── Event delegation ────────────────────────────────── var tbl = document.getElementById('btbl'); if(!tbl) return; // Column header label click → editor tbl.querySelectorAll('.bth-label').forEach(function(span) { span.addEventListener('click', function(e) { e.stopPropagation(); openColEditor(e, parseInt(span.dataset.aci)); }); }); // Add column button var addBtn = document.getElementById('add-col-btn'); if(addBtn) addBtn.addEventListener('click', addBudgetCol); // Cell edit click tbl.querySelectorAll('.bedit-cell').forEach(function(td) { td.addEventListener('click', function() { var span = td.querySelector('.ec'); bInline(span, 'budget', td.dataset.bid, td.dataset.field, td.dataset.type); }); }); // Status cell click tbl.querySelectorAll('.bstat-cell').forEach(function(td) { td.addEventListener('click', function() { var col = getBCols()[parseInt(td.dataset.aci)]; if(col) editBStat(td.dataset.bid, td.dataset.colid, col, td); }); }); // Color dot click tbl.querySelectorAll('.color-dot').forEach(function(dot) { dot.addEventListener('click', function(e) { e.stopPropagation(); openCP(e, dot.dataset.bid, dot.dataset.field, dot.dataset.col); }); }); // Delete button tbl.querySelectorAll('.bdel-btn').forEach(function(btn) { btn.addEventListener('click', function() { dbDelete('budget', btn.dataset.bid); }); }); // Date input tbl.querySelectorAll('.bdate-inp').forEach(function(inp) { inp.addEventListener('change', function() { var d={}; d[inp.dataset.field]=inp.value; dbUpdate('budget',inp.dataset.bid,d); }); }); // File inputs tbl.querySelectorAll('.bfile-inp').forEach(function(inp) { inp.addEventListener('change', function() { attachFile(inp.dataset.bid,inp.dataset.field,inp); }); }); tbl.querySelectorAll('.bfile-dl').forEach(function(a) { a.addEventListener('click', function(e) { e.preventDefault(); downloadFile(e,a.dataset.bid,a.dataset.field); }); }); tbl.querySelectorAll('.bfile-clr').forEach(function(s) { s.addEventListener('click', function() { clearFile(s.dataset.bid,s.dataset.field); }); }); // Row drag & drop tbl.querySelectorAll('.brow').forEach(function(tr) { var bid = tr.dataset.bid; tr.addEventListener('dragstart', function(e){ bRowStart(e,bid); }); tr.addEventListener('dragover', function(e){ bRowOver(e,bid); }); tr.addEventListener('dragleave', function(e){ bRowLeave(e); }); tr.addEventListener('drop', function(e){ bRowDrop(e,bid); }); tr.addEventListener('dragend', function(){ bRowEnd(); }); }); // Inline add row var qadd = document.getElementById('qadd-tr'); if(qadd) { var qph = document.getElementById('qadd-ph'); if(qph) qph.addEventListener('click', activateInlineAdd); var qok = document.getElementById('qadd-ok'); if(qok) qok.addEventListener('click', doQuickAdd); var qcancel = document.getElementById('qadd-cancel'); if(qcancel) qcancel.addEventListener('click', deactivateInlineAdd); var qname = document.getElementById('qadd-name'); if(qname) qname.addEventListener('keydown', qadd_key); var qttc = document.getElementById('qadd-ttc'); if(qttc) qttc.addEventListener('keydown', qadd_key); } // Column resize tbl.querySelectorAll('.rh').forEach(function(handle) { handle.addEventListener('pointerdown', function(e) { e.preventDefault(); e.stopPropagation(); var ci = parseInt(handle.dataset.ci); var visCols2 = getBCols().filter(function(x){return x.vis;}); var col = visCols2[ci]; if(!col) return; var startX=e.clientX, startW=col.w, th=handle.parentElement; handle.setPointerCapture(e.pointerId); document.body.style.cursor='col-resize'; function onMove(ev){ col.w=Math.max(40,startW+ev.clientX-startX); if(th){th.style.minWidth=col.w+'px';th.style.width=col.w+'px';} } function onUp(){ document.body.style.cursor=''; saveBCols(); handle.removeEventListener('pointermove',onMove); handle.removeEventListener('pointerup',onUp); } handle.addEventListener('pointermove',onMove); handle.addEventListener('pointerup',onUp); }); }); }