/
home
/
oxicore
/
public_html
/
Upload File
HOME
<!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Painel Petro Posto | Oficial</title> <script src="https://cdn.tailwindcss.com"></script> <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script> <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> <script src="https://unpkg.com/@supabase/supabase-js@2"></script> <script src="https://unpkg.com/lucide@latest"></script> </head> <body class="bg-gray-100 text-gray-800"> <div id="root"></div> <script type="text/babel"> // 👇👇👇 SUAS CHAVES AQUI 👇👇👇 const SUPABASE_URL = 'https://fqogvyvppowpmkdcazfd.supabase.co'; const SUPABASE_KEY = 'sb_publishable_lTatTmXAr3DYKIM31K5f9A_UJTSsluG'; // 👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆 const { createClient } = supabase; const _supabase = createClient(SUPABASE_URL, SUPABASE_KEY); // 🔒 SENHA DO ADMINISTRADOR const SENHA_ADMIN = "94730"; function App() { const [session, setSession] = React.useState(null); const [loadingAuth, setLoadingAuth] = React.useState(true); React.useEffect(() => { _supabase.auth.getSession().then(({ data: { session } }) => { setSession(session); setLoadingAuth(false); }); const { data: { subscription } } = _supabase.auth.onAuthStateChange((_event, session) => { setSession(session); }); return () => subscription.unsubscribe(); }, []); if (loadingAuth) return <div className="h-screen flex items-center justify-center">Carregando...</div>; return ( <div className="min-h-screen"> {!session ? <LoginScreen /> : <Dashboard session={session} />} </div> ); } function LoginScreen() { const [email, setEmail] = React.useState(''); const [password, setPassword] = React.useState(''); const [loading, setLoading] = React.useState(false); const handleLogin = async (e) => { e.preventDefault(); setLoading(true); const { error } = await _supabase.auth.signInWithPassword({ email, password }); if (error) alert("Erro no login: " + error.message); setLoading(false); }; return ( <div className="flex items-center justify-center h-screen bg-blue-900"> <form onSubmit={handleLogin} className="bg-white p-8 rounded-lg shadow-2xl w-96"> <div className="flex justify-center mb-6 text-blue-600"> <i data-lucide="fuel" className="w-12 h-12"></i> </div> <h2 className="text-2xl font-bold text-center mb-6 text-gray-800">Petro Posto Xingu</h2> <div className="mb-4"> <label className="block text-sm font-bold mb-2">Email</label> <input type="email" required className="w-full p-3 border rounded" value={email} onChange={e => setEmail(e.target.value)} /> </div> <div className="mb-6"> <label className="block text-sm font-bold mb-2">Senha</label> <input type="password" required className="w-full p-3 border rounded" value={password} onChange={e => setPassword(e.target.value)} /> </div> <button disabled={loading} className="w-full bg-blue-600 text-white font-bold py-3 rounded hover:bg-blue-700 transition"> {loading ? 'Entrando...' : 'Acessar Painel'} </button> </form> </div> ); } function Dashboard({ session }) { const [transacoes, setTransacoes] = React.useState([]); const [loading, setLoading] = React.useState(true); const [filtros, setFiltros] = React.useState({ nome: '', cpf: '', telefone: '' }); // Estados do Modal de Edição const [editModal, setEditModal] = React.useState(null); const [novoValor, setNovoValor] = React.useState(''); const [senhaInput, setSenhaInput] = React.useState(''); // Campo da senha // --- LÓGICA DE JOIN MANUAL (MANTIDA) --- const fetchDados = async () => { setLoading(true); const { data: dadosTransacoes, error: erroT } = await _supabase .from('transacoes') .select('*') .order('created_at', { ascending: false }); if (erroT) { alert("Erro ao buscar transações: " + erroT.message); setLoading(false); return; } const { data: dadosClientes, error: erroC } = await _supabase .from('clientes') .select('*'); if (erroC) { alert("Erro ao buscar clientes: " + erroC.message); setLoading(false); return; } const mapaClientes = {}; dadosClientes.forEach(cliente => { mapaClientes[cliente.id] = cliente; }); const dadosCompletos = dadosTransacoes.map(transacao => { return { ...transacao, clientes: mapaClientes[transacao.cliente_id] || {} }; }); setTransacoes(dadosCompletos); setLoading(false); }; React.useEffect(() => { fetchDados(); }, []); React.useEffect(() => { lucide.createIcons(); }); const toggleCashback = async (id, statusAtual) => { const novoStatus = !statusAtual; const dataResgate = novoStatus ? new Date().toISOString() : null; setTransacoes(prev => prev.map(t => t.id === id ? { ...t, cashback_resgatado: novoStatus, data_resgate: dataResgate } : t)); const { error } = await _supabase.from('transacoes').update({ cashback_resgatado: novoStatus, data_resgate: dataResgate }).eq('id', id); if (error) { alert("Erro ao salvar: " + error.message); fetchDados(); } }; // --- LÓGICA DE SALVAR COM SENHA --- const salvarNovoValor = async () => { // 1. Verifica a senha if (senhaInput !== SENHA_ADMIN) { alert("⛔ SENHA DE ADMINISTRADOR INCORRETA!"); return; } // 2. Salva no banco const { error } = await _supabase.from('transacoes').update({ valor_abastecimento: parseFloat(novoValor) }).eq('id', editModal.id); if (error) return alert("Erro ao salvar: " + error.message); // 3. Atualiza na tela setTransacoes(prev => prev.map(t => t.id === editModal.id ? { ...t, valor_abastecimento: parseFloat(novoValor) } : t)); setEditModal(null); setSenhaInput(''); // Limpa a senha }; const abrirModal = (item) => { setEditModal(item); setNovoValor(item.valor_abastecimento); setSenhaInput(''); // Reseta o campo de senha ao abrir }; const handleLogout = async () => { await _supabase.auth.signOut(); }; const dadosFiltrados = transacoes.filter(t => { const cliente = t.clientes; const nome = cliente?.nome_completo?.toLowerCase() || ''; const cpf = cliente?.cpf || ''; const whats = cliente?.whatsapp || ''; return nome.includes(filtros.nome.toLowerCase()) && cpf.includes(filtros.cpf) && whats.includes(filtros.telefone); }); return ( <div className="max-w-7xl mx-auto p-4 md:p-8"> {/* AQUI MUDOU A COR DA BARRA PARA VERMELHO (border-red-600) */} <header className="mb-8 flex justify-between items-center bg-white p-6 rounded-lg shadow border-l-4 border-red-600"> <div> <h1 className="text-2xl md:text-3xl font-bold text-gray-800">Painel Administrativo</h1> <p className="text-gray-500 text-sm">Logado como: {session.user.email}</p> </div> <div className="flex gap-3"> <button onClick={fetchDados} className="bg-gray-100 text-gray-700 px-4 py-2 rounded hover:bg-gray-200 flex items-center gap-2"> <i data-lucide="refresh-cw" className="w-4 h-4"></i> Atualizar </button> <button onClick={handleLogout} className="bg-red-50 text-red-600 px-4 py-2 rounded hover:bg-red-100 font-bold text-sm"> Sair </button> </div> </header> <div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6 bg-white p-4 rounded shadow-sm"> <div className="relative"> <i data-lucide="search" className="absolute left-3 top-3 text-gray-400 w-4 h-4"></i> <input className="w-full pl-9 p-2 border rounded outline-none focus:border-blue-500" placeholder="Nome..." value={filtros.nome} onChange={e => setFiltros({...filtros, nome: e.target.value})} /> </div> <input className="w-full p-2 border rounded outline-none focus:border-blue-500" placeholder="CPF..." value={filtros.cpf} onChange={e => setFiltros({...filtros, cpf: e.target.value})} /> <input className="w-full p-2 border rounded outline-none focus:border-blue-500" placeholder="Telefone..." value={filtros.telefone} onChange={e => setFiltros({...filtros, telefone: e.target.value})} /> </div> <div className="bg-white rounded-lg shadow overflow-hidden overflow-x-auto"> <table className="w-full text-left border-collapse min-w-[800px]"> <thead className="bg-gray-50 text-gray-600 font-bold uppercase text-xs tracking-wider"> <tr> <th className="p-4">Data</th> <th className="p-4">Cliente</th> <th className="p-4">Unidade</th> <th className="p-4">Valor</th> <th className="p-4 text-center">Cupom</th> <th className="p-4 text-center">Status</th> <th className="p-4 text-right">Ações</th> </tr> </thead> <tbody className="divide-y divide-gray-100"> {loading ? <tr><td colSpan="7" className="p-8 text-center text-gray-500">Carregando dados...</td></tr> : dadosFiltrados.length === 0 ? <tr><td colSpan="7" className="p-8 text-center text-gray-500">Nenhuma transação encontrada.</td></tr> : dadosFiltrados.map(item => ( <tr key={item.id} className="hover:bg-blue-50 transition-colors group"> <td className="p-4 text-sm text-gray-500"> {new Date(item.created_at).toLocaleDateString('pt-BR')} <br/> <span className="text-xs">{new Date(item.created_at).toLocaleTimeString('pt-BR', {hour: '2-digit', minute:'2-digit'})}</span> </td> <td className="p-4"> <div className="font-bold text-gray-800">{item.clientes?.nome_completo || 'Sem Nome'}</div> <div className="text-xs text-gray-500">CPF: {item.clientes?.cpf || '-'}</div> <div className="text-xs text-gray-500">Tel: {item.clientes?.whatsapp || '-'}</div> </td> <td className="p-4 text-sm font-medium text-blue-900">{item.unidade}</td> <td className="p-4 font-mono font-bold text-green-700 text-lg">R$ {item.valor_abastecimento?.toFixed(2)}</td> <td className="p-4 text-center"> {item.foto_cupom_url ? <a href={item.foto_cupom_url} target="_blank" className="inline-flex items-center gap-1 text-blue-600 bg-blue-50 px-3 py-1 rounded-full text-xs font-bold hover:bg-blue-100"> VER <i data-lucide="external-link" className="w-3 h-3"></i> </a> : <span className="text-gray-300">-</span> } </td> <td className="p-4 text-center"> <button onClick={() => toggleCashback(item.id, item.cashback_resgatado)} className={`px-3 py-1 rounded-full text-xs font-bold w-28 border transition-all ${item.cashback_resgatado ? 'bg-green-100 text-green-800 border-green-200' : 'bg-yellow-50 text-yellow-800 border-yellow-200 hover:bg-yellow-100'}`} > {item.cashback_resgatado ? '✅ RESGATADO' : '⏳ PENDENTE'} </button> </td> <td className="p-4 text-right"> <button onClick={() => abrirModal(item)} className="text-gray-400 hover:text-blue-600 p-2 rounded-full hover:bg-gray-100"> <i data-lucide="edit-2" className="w-4 h-4"></i> </button> </td> </tr> ))} </tbody> </table> </div> {editModal && ( <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4 backdrop-blur-sm"> <div className="bg-white p-6 rounded-xl shadow-2xl w-full max-w-sm transform transition-all scale-100 border-l-4 border-red-500"> <h3 className="font-bold text-lg mb-1 text-gray-800 flex items-center gap-2"> <i data-lucide="lock" className="w-5 h-5 text-red-500"></i> Área Segura </h3> <p className="text-sm text-gray-500 mb-4">Alteração de valores auditada.</p> <label className="block text-xs font-bold text-gray-500 uppercase mb-1">Novo Valor (R$)</label> <input type="number" className="w-full border-2 border-gray-200 p-3 rounded-lg mb-4 text-lg font-bold text-gray-800 focus:border-blue-500 outline-none" value={novoValor} onChange={e => setNovoValor(e.target.value)} /> <label className="block text-xs font-bold text-gray-500 uppercase mb-1">Senha de Administrador</label> <input type="password" className="w-full border-2 border-red-100 p-3 rounded-lg mb-6 text-gray-800 focus:border-red-500 outline-none bg-red-50" placeholder="Digite a senha..." value={senhaInput} onChange={e => setSenhaInput(e.target.value)} /> <div className="flex gap-3"> <button onClick={() => setEditModal(null)} className="flex-1 bg-gray-100 text-gray-600 p-3 rounded-lg font-bold hover:bg-gray-200">Cancelar</button> <button onClick={salvarNovoValor} className="flex-1 bg-red-600 text-white p-3 rounded-lg font-bold hover:bg-red-700">Confirmar</button> </div> </div> </div> )} </div> ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />); </script> </body> </html>