Files
html/mission-billing.html

155 lines
8.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html><html lang="fr"><head><meta charset="UTF-8"><title>Mission Billing — WEVAL</title>
<style>
body{font-family:system-ui;background:#0a0e1a;color:#e2e8f0;margin:0;padding:18px}
h1{color:#a5b4fc;font-size:1.3rem;margin:0 0 4px}
.sub{color:#64748b;font-size:.82rem;margin-bottom:14px}
.breadcrumb{color:#64748b;font-size:.78rem;margin-bottom:8px}
.breadcrumb a{color:#a5b4fc;text-decoration:none}
.sel-row{display:flex;gap:10px;align-items:center;margin-bottom:16px;background:#151e33;padding:12px;border-radius:8px;flex-wrap:wrap}
select, input{background:#0a0e1a;border:1px solid #1e293b;color:#e2e8f0;padding:8px 10px;border-radius:6px;font:.85rem system-ui}
select:focus, input:focus{border-color:#6366f1;outline:none}
.btn{padding:8px 14px;background:#6366f1;color:#fff;border:none;border-radius:6px;cursor:pointer;font-weight:500;font-size:.85rem}
.btn:hover{background:#4f46e5}
.mission-info{background:#151e33;padding:14px;border-radius:8px;margin-bottom:14px}
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;margin-bottom:16px}
.kpi{background:#151e33;border:1px solid #1e293b;border-radius:8px;padding:12px}
.kpi-val{font-size:1.4rem;color:#22d3ee;font-weight:700}
.kpi-lbl{color:#94a3b8;font-size:.7rem;text-transform:uppercase}
table{width:100%;border-collapse:collapse;font-size:.83rem;background:#151e33;border-radius:8px;overflow:hidden}
th{background:#1e1b4b;color:#a5b4fc;padding:10px 8px;text-align:left;font-size:.72rem;text-transform:uppercase;letter-spacing:.3px}
td{padding:10px 8px;border-bottom:1px solid #1e293b}
td.num{text-align:right;font-family:'JetBrains Mono',monospace}
tr:hover td{background:#1e293b}
.tot-row td{background:#1e1b4b;font-weight:700;color:#a5b4fc;font-size:.95rem;border-top:2px solid #6366f1}
.add-form{background:#151e33;padding:14px;border-radius:8px;margin-top:14px;display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.tag{background:#0a0e1a;border:1px solid #334155;color:#94a3b8;padding:2px 8px;border-radius:3px;font-size:.72rem}
</style></head>
<body>
<div class="breadcrumb"><a href="/">Home</a> / <a href="/candidates-pool.html">Candidates</a> / Mission Billing</div>
<h1>💰 Mission Billing — Simulation Facturation</h1>
<div class="sub">Style BASELINE — TJM × Jours × Mois — Commissions apporteur/manager</div>
<div class="sel-row">
<label>Mission:</label>
<select id="sel-mission" onchange="loadMission()"></select>
<button class="btn" onclick="loadMission()">↻ Refresh</button>
</div>
<div id="content">Loading missions...</div>
<script>
const TENANT = new URLSearchParams(location.search).get('tenant') || 'weval';
let currentMission = null;
async function init() {
const r = await fetch(`/api/em/missions?tenant=${TENANT}`);
const d = await r.json();
const sel = document.getElementById('sel-mission');
sel.innerHTML = (d.missions || []).map(m =>
`<option value="${m.id}">${m.mission_code}${m.client_name || m.client_code} (${m.consultant_name || '—'})</option>`
).join('') || '<option value="">Aucune mission</option>';
if (d.missions && d.missions.length) { sel.value = d.missions[0].id; loadMission(); }
}
async function loadMission() {
const id = document.getElementById('sel-mission').value;
if (!id) return;
const r = await fetch(`/api/em/missions/${id}?tenant=${TENANT}`);
currentMission = await r.json();
render();
}
function render() {
const m = currentMission;
if (!m) return;
const billing = m.billing || [];
const totalDays = billing.reduce((s,b) => s + parseFloat(b.days_worked || 0), 0);
const totalGross = billing.reduce((s,b) => s + parseFloat(b.gross_amount || 0), 0);
const totalCash = billing.reduce((s,b) => s + parseFloat(b.cash_consultant || 0), 0);
const totalChafik = billing.reduce((s,b) => s + parseFloat(b.gross_amount||0) * parseFloat(b.commission_chafik||0), 0);
const totalYoussef = billing.reduce((s,b) => s + parseFloat(b.gross_amount||0) * parseFloat(b.commission_youssef||0), 0);
let html = `
<div class="mission-info">
<strong style="font-size:1rem;color:#a5b4fc">${m.mission_code}</strong> —
<span class="tag">${m.client_name || m.client_code}</span>
<span class="tag">Consultant: ${m.consultant_name || '—'}</span>
<span class="tag">${m.role || '—'}</span>
<span class="tag">TJM: ${parseFloat(m.tjm).toLocaleString('fr-FR')} MAD</span>
<span class="tag">Statut: ${m.status}</span>
<span class="tag">Start: ${m.start_date || '—'}</span>
</div>
<div class="kpis">
<div class="kpi"><div class="kpi-val">${totalDays.toFixed(1)}</div><div class="kpi-lbl">Jours total</div></div>
<div class="kpi"><div class="kpi-val">${Math.round(totalGross).toLocaleString('fr-FR')}</div><div class="kpi-lbl">Brut (MAD)</div></div>
<div class="kpi"><div class="kpi-val" style="color:#10b981">${Math.round(totalCash).toLocaleString('fr-FR')}</div><div class="kpi-lbl">Cash consultant</div></div>
<div class="kpi"><div class="kpi-val" style="color:#f59e0b">${Math.round(totalChafik).toLocaleString('fr-FR')}</div><div class="kpi-lbl">Com. Chafik (5%)</div></div>
<div class="kpi"><div class="kpi-val" style="color:#a855f7">${Math.round(totalYoussef).toLocaleString('fr-FR')}</div><div class="kpi-lbl">Com. Youssef (25%)</div></div>
<div class="kpi"><div class="kpi-val">${billing.length}</div><div class="kpi-lbl">Périodes</div></div>
</div>
<table><thead><tr>
<th>Mois</th><th>J/Homme</th><th>TJM</th><th>Brut</th>
<th>Com. Chafik</th><th>Com. Youssef</th><th>Cash Consultant</th><th>Facturé</th><th>Payé</th>
</tr></thead><tbody>`;
billing.forEach(b => {
const gross = parseFloat(b.gross_amount || 0);
const cChafik = gross * parseFloat(b.commission_chafik || 0);
const cYoussef = gross * parseFloat(b.commission_youssef || 0);
const cash = parseFloat(b.cash_consultant || 0);
const month = new Date(b.period_month).toLocaleDateString('fr-FR', {month:'long', year:'numeric'});
html += `<tr>
<td><strong>${month}</strong></td>
<td class="num">${parseFloat(b.days_worked).toFixed(1)}</td>
<td class="num">${parseFloat(b.tjm_applied).toLocaleString('fr-FR')}</td>
<td class="num">${Math.round(gross).toLocaleString('fr-FR')}</td>
<td class="num" style="color:#f59e0b">${Math.round(cChafik).toLocaleString('fr-FR')}</td>
<td class="num" style="color:#a855f7">${Math.round(cYoussef).toLocaleString('fr-FR')}</td>
<td class="num" style="color:#10b981"><strong>${Math.round(cash).toLocaleString('fr-FR')}</strong></td>
<td>${b.invoiced ? '✅' : '—'}</td>
<td>${b.paid ? '✅' : '—'}</td>
</tr>`;
});
html += `<tr class="tot-row">
<td>TOTAL</td>
<td class="num">${totalDays.toFixed(1)}</td><td>—</td>
<td class="num">${Math.round(totalGross).toLocaleString('fr-FR')}</td>
<td class="num">${Math.round(totalChafik).toLocaleString('fr-FR')}</td>
<td class="num">${Math.round(totalYoussef).toLocaleString('fr-FR')}</td>
<td class="num">${Math.round(totalCash).toLocaleString('fr-FR')}</td>
<td>—</td><td>—</td>
</tr></tbody></table>
<div class="add-form">
<strong style="color:#a5b4fc">+ Ajouter période</strong>
<input id="new-period" type="month" value="${new Date().toISOString().substring(0,7)}">
<input id="new-days" type="number" step="0.5" placeholder="Jours" style="width:90px">
<input id="new-tjm" type="number" placeholder="TJM" value="${m.tjm || 2470}" style="width:100px">
<button class="btn" onclick="addPeriod()">Ajouter</button>
</div>
`;
document.getElementById('content').innerHTML = html;
}
async function addPeriod() {
const period = document.getElementById('new-period').value + '-01';
const days = parseFloat(document.getElementById('new-days').value);
const tjm = parseFloat(document.getElementById('new-tjm').value);
if (!days || !tjm) { alert('Jours + TJM requis'); return; }
const r = await fetch(`/api/em/missions/${currentMission.id}/billing`, {
method:'POST', headers:{'Content-Type':'application/json'},
body: JSON.stringify({period_month: period, days_worked: days, tjm_applied: tjm})
});
const d = await r.json();
if (d.ok) { alert(`✅ Facturé: ${Math.round(d.gross).toLocaleString('fr-FR')} MAD (cash ${Math.round(d.cash_consultant).toLocaleString('fr-FR')})`); loadMission(); }
else alert('❌ '+d.error);
}
init();
</script></body></html>