feat: Meshy.ai — raw cost in cout_fixe, margin in variable, per-job margin %
Deploy via Portainer / deploy (push) Successful in 1s

This commit is contained in:
Jo
2026-07-16 14:54:13 +02:00
parent 15ae5c5d77
commit 0619559190
4 changed files with 60 additions and 34 deletions
+6 -4
View File
@@ -595,7 +595,7 @@ document.getElementById('materialSelect').addEventListener('change', function()
});
// ── Autres champs → recalc ────────────────────────────────────────────────────
['weight_g','hours','minutes','discount_pct','pieces_per_plate','order_qty','meshy_credits_used'].forEach(id => {
['weight_g','hours','minutes','discount_pct','pieces_per_plate','order_qty','meshy_credits_used','meshy_margin_pct'].forEach(id => {
const el = document.getElementById(id);
if (el) el.addEventListener('input', recalc);
});
@@ -627,6 +627,7 @@ function recalc() {
order_qty: parseInt(document.getElementById('order_qty').value) || 1,
meshy_enabled: document.getElementById('meshy_enabled').checked,
meshy_credits_used: parseInt(document.getElementById('meshy_credits_used').value) || 0,
meshy_margin_pct: parseFloat(document.getElementById('meshy_margin_pct').value) || 0,
};
fetch('/api/calculate', {
@@ -637,9 +638,9 @@ function recalc() {
.then(r => r.json())
.then(d => {
renderBreakdown(d, body);
if (d.meshy_unit_cost) {
if (d.meshy_unit_cost && body.meshy_enabled) {
document.getElementById('meshyCostHint').innerHTML =
`<span class="text-muted">Coût unitaire : ${d.meshy_unit_cost.toFixed(4)}/crédit</span>`;
`<span class="text-muted">${d.meshy_unit_cost.toFixed(4)} €/crédit · coût brut : ${d.meshy_cost.toFixed(2)} € · marge : ${d.meshy_margin_amount.toFixed(2)} €</span>`;
}
})
.catch(() => {});
@@ -759,12 +760,13 @@ function renderBreakdown(d, body) {
${row(`<span class="breakdown-muted ps-2">Usure — buse</span>`, d.nozzle_wear, '', true)}
${row(`<span class="breakdown-muted ps-2">Usure — plateau</span>`, d.plate_wear, '', true)}
${row(`<span class="breakdown-muted ps-2">Electricite <small class="text-secondary">${parseFloat(d.kwh_used).toFixed(3)} kWh × ${d._elec_price} €</small></span>`, d.electricity_cost, '', true)}
${body.meshy_enabled && d.meshy_cost > 0 ? row(`<span class="breakdown-muted ps-2" style="color:#7c3aed"><i class="bi bi-stars me-1"></i>Meshy.ai — coût abonnement (${body.meshy_credits_used} crédits)</span>`, d.meshy_cost, '', true) : ''}
${row(`<span class="fw-semibold">Total cout fixe</span>`, d.cout_fixe, 'subtotal')}
<div class="breakdown-row section-header"><span>Partie variable</span></div>
${row(`<span class="breakdown-muted ps-2">Manutention <small class="text-secondary">${d._handling_minutes} min × ${d._handling_rate} €/h</small></span>`, d.handling_cost, '', true)}
${row(`<span class="breakdown-muted ps-2">Design (x${dm})</span>`, d.design_cost, '', true)}
${body.meshy_enabled && d.meshy_cost > 0 ? row(`<span class="breakdown-muted ps-2" style="color:#7c3aed"><i class="bi bi-stars me-1"></i>Meshy.ai (${body.meshy_credits_used} crédits)</span>`, d.meshy_cost, '', true) : ''}
${body.meshy_enabled && d.meshy_margin_amount > 0 ? row(`<span class="breakdown-muted ps-2" style="color:#7c3aed"><i class="bi bi-stars me-1"></i>Marge Meshy.ai (${body.meshy_margin_pct}%)</span>`, d.meshy_margin_amount, '', true) : ''}
${row(`<span class="breakdown-muted ps-2">Marge brute (${mgn}%)</span>`, d.margin_amount)}
${row(`<span class="fw-semibold">Total marge <small class="text-muted fw-normal">(${d.marge_pct_on_ht}% du HT)</small></span>`, d.total_marge, 'subtotal')}