Olá,
Nenhum registro no histórico ainda.'; } var sorted = r.historico.slice().reverse(); return sorted.map(function(h) { var iconCls = h.tipo==='status'?'status':h.tipo==='obs'?'obs':h.tipo==='foto'?'foto':'entrada'; var iconTxt = h.tipo==='status'?'🔄':h.tipo==='obs'?'📝':h.tipo==='foto'?'📸':'📦'; var titulo = ''; var detalhe = ''; if(h.tipo==='status') { titulo = h.de ? 'Status atualizado' : 'Produto registrado'; detalhe = h.de ? ''+h.de+''+h.para+'' : ''+h.para+''; } else if(h.tipo==='obs') { titulo = 'Observação adicionada'; detalhe = ''+h.texto+''; } else if(h.tipo==='foto') { titulo = 'Foto adicionada'; detalhe = h.texto; } return '
' + '
'+iconTxt+'
' + '
' + '
'+titulo+'
' + '
'+detalhe+'
' + '
🕐 '+h.data+'👤 '+h.usuario+'
' + '
' + '
'; }).join(''); } function openRMADetail(id) { var r = rmas.find(function(x){ return x.id === id; }); if(!r) return; var prazoClass = function(prazo, status) { if(status==='Entregue') return ''; var d = new Date(prazo), hoje = new Date(); hoje.setHours(0,0,0,0); var diff = Math.floor((d-hoje)/86400000); if(diff<0) return 'prazo-atrasado'; if(diff<=3) return 'prazo-urgente'; return ''; }; var prazoText = function(prazo, status) { if(status==='Entregue') return 'Entregue'; var d = new Date(prazo), hoje = new Date(); hoje.setHours(0,0,0,0); var diff = Math.floor((d-hoje)/86400000); if(diff<0) return 'Venceu há '+Math.abs(diff)+'d'; if(diff===0) return 'Vence hoje'; return 'Vence '+formatDate(prazo); }; var isGerente = sessao && sessao.perfil === 'gerente'; document.getElementById('rmaDetailPanel').innerHTML = '
'+ '
'+r.iniciais+'
'+ '
'+ '
'+r.cliente+'
'+ '
'+r.id+'
'+ '
'+ '
'+ '
'+ '
Informações do produto
'+ '
Produto'+r.produto+'
'+ '
Serial'+r.serial+'
'+ '
Telefone'+r.tel+'
'+ '
Defeito'+r.defeito+'
'+ '
Técnico'+r.tecnico+'
'+ '
Entrada'+formatDate(r.entrada)+'
'+ '
Prazo'+prazoText(r.prazo,r.status)+'
'+ '
'+ '
'+ '
Atualizar status
'+ ''+ '
'+ '
'+ '
Histórico completo
'+ '
'+renderHistorico(r)+'
'+ '
'+ '
'+ '
Nova observação técnica
'+ ''+ '
'+ ''+ '
'+ '
'+ (r.fotos>0?'
Fotos ('+r.fotos+')
'+ Array(r.fotos).fill(0).map(function(){ return '
'; }).join('')+ '
':'')+ ''; document.getElementById('rmaDetailPanel').classList.add('open'); document.getElementById('rmaOverlay').classList.add('open'); } function closeRMADetail() { document.getElementById('rmaDetailPanel').classList.remove('open'); document.getElementById('rmaOverlay').classList.remove('open'); } function addRMAObs(id) { var r = rmas.find(function(x){ return x.id === id; }); var inp = document.getElementById('obsInput-'+id); var txt = inp.value.trim(); if(!txt) return; var now = new Date().toLocaleString('pt-BR'); var usuario = sessao ? sessao.nome : 'Técnico'; if(!r.historico) r.historico = []; if(!r.obs) r.obs = []; r.obs.push({txt:txt, time:now}); r.historico.push({tipo:'obs', texto:txt, data:now, usuario:usuario}); window.db.collection('rmas').doc(id).update({ obs: r.obs, historico: r.historico, atualizadoEm: new Date().toISOString() }).then(function(){ inp.value = ''; var histList = document.getElementById('hist-list-'+id); if(histList) histList.innerHTML = renderHistorico(r); showToast('Observação salva!'); }).catch(function(e){ showToast('Erro: '+e.message); }); } function marcarEntregue(id) { var r = rmas.find(function(x){ return x.id === id; }); if(!r) return; var now = new Date().toLocaleString('pt-BR'); var usuario = sessao ? sessao.nome : 'Técnico'; if(!r.historico) r.historico = []; r.historico.push({tipo:'status', de:r.status, para:'Entregue', data:now, usuario:usuario}); r.status = 'Entregue'; window.db.collection('rmas').doc(id).update({ status: 'Entregue', historico: r.historico, atualizadoEm: new Date().toISOString() }).then(function(){ closeRMADetail(); renderRMAList(); showToast('Produto marcado como entregue!'); }).catch(function(e){ showToast('Erro: '+e.message); }); } function showToast(msg) { var t = document.getElementById('toast'); t.textContent = msg; t.classList.add('show'); setTimeout(function(){ t.classList.remove('show'); }, 2500); } function gerarRecibo(id) { var r = rmas.find(function(x){ return x.id === id; }); if(!r) return; var { jsPDF } = window.jspdf; var doc = new jsPDF(); var verde = [27, 94, 59]; var creme = [245, 240, 232]; // Fundo doc.setFillColor(creme[0], creme[1], creme[2]); doc.rect(0, 0, 210, 297, 'F'); // Header doc.setFillColor(verde[0], verde[1], verde[2]); doc.rect(0, 0, 210, 40, 'F'); doc.setTextColor(255,255,255); doc.setFont('helvetica','bold'); doc.setFontSize(28); doc.text('MYA', 20, 20); doc.setFontSize(10); doc.setFont('helvetica','normal'); doc.text('SISTEMA DE GESTÃO', 20, 28); doc.setFontSize(12); doc.text('COMPROVANTE DE CONSERTO', 210-20, 20, {align:'right'}); doc.setFontSize(10); doc.text(r.id, 210-20, 28, {align:'right'}); // Dados doc.setTextColor(27,94,59); doc.setFont('helvetica','bold'); doc.setFontSize(14); doc.text('Dados do Cliente', 20, 58); doc.setDrawColor(verde[0], verde[1], verde[2]); doc.setLineWidth(0.5); doc.line(20, 61, 190, 61); doc.setFont('helvetica','normal'); doc.setFontSize(11); doc.setTextColor(80,80,80); var y = 72; var rows = [ ['Cliente', r.cliente], ['Telefone', r.tel], ['Produto', r.produto], ['Serial', r.serial], ['Defeito', r.defeito], ['Técnico', r.tecnico], ['Entrada', formatDate(r.entrada)], ['Prazo', formatDate(r.prazo)], ['Status', r.status], ]; rows.forEach(function(row) { doc.setFont('helvetica','bold'); doc.setTextColor(27,94,59); doc.text(row[0]+':', 20, y); doc.setFont('helvetica','normal'); doc.setTextColor(80,80,80); doc.text(String(row[1]), 70, y); y += 9; }); // Barra de progresso y += 8; doc.setFont('helvetica','bold'); doc.setTextColor(27,94,59); doc.setFontSize(14); doc.text('Progresso do Conserto', 20, y); doc.line(20, y+3, 190, y+3); y += 14; var stepW = 28; RMA_STEPS.forEach(function(step, i) { var x = 20 + i * stepW; var done = RMA_STEPS.indexOf(r.status) >= i; doc.setFillColor(done?verde[0]:200, done?verde[1]:200, done?verde[2]:200); doc.circle(x+14, y, 5, 'F'); doc.setFontSize(7); doc.setTextColor(done?27:150, done?94:150, done?59:150); doc.text(RMA_STEP_LABELS[i], x+14, y+10, {align:'center'}); }); // Rodapé doc.setFillColor(verde[0], verde[1], verde[2]); doc.rect(0, 272, 210, 25, 'F'); doc.setTextColor(255,255,255); doc.setFontSize(9); doc.text('MYA — Sistema de Gestão', 20, 283); doc.text('Emitido em: '+new Date().toLocaleString('pt-BR'), 210-20, 283, {align:'right'}); doc.save('recibo-'+r.id+'.pdf'); showToast('Recibo gerado!'); }