feat(safety): invoice reconciliation on order detail

Add invoice total comparison in the order detail modal. When an order
has been invoiced, shows whether the invoice total matches the order
total — green badge if OK, red badge with difference amount if not.

Backend: compute reconciliation (difference, match) from existing
invoice.total_cu_tva vs order_total in order_detail endpoint.

Frontend: reconciliation badge below invoice info in modal, hidden
when no invoice exists.

Cache-bust: shared.js?v=17

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-03-27 12:30:21 +00:00
parent a10a00aa4d
commit 1b2b1d8b24
3 changed files with 33 additions and 1 deletions

View File

@@ -481,6 +481,8 @@ async function renderOrderDetailModal(orderNumber, opts) {
if (mobileContainer) mobileContainer.innerHTML = '';
const priceCheckEl = document.getElementById('detailPriceCheck');
if (priceCheckEl) priceCheckEl.innerHTML = '';
const reconEl = document.getElementById('detailInvoiceRecon');
if (reconEl) { reconEl.innerHTML = ''; reconEl.style.display = 'none'; }
const modalEl = document.getElementById('orderDetailModal');
const existing = bootstrap.Modal.getInstance(modalEl);
@@ -529,6 +531,22 @@ async function renderOrderDetailModal(orderNumber, opts) {
if (invInfo) invInfo.style.display = '';
}
// Invoice reconciliation
const reconEl = document.getElementById('detailInvoiceRecon');
if (reconEl && inv && inv.reconciliation) {
const r = inv.reconciliation;
if (r.match) {
reconEl.innerHTML = `<span class="badge" style="background:var(--success-light);color:var(--success-text)">✓ Total factura OK (${fmtNum(r.invoice_total)} lei)</span>`;
} else {
const sign = r.difference > 0 ? '+' : '';
reconEl.innerHTML = `<span class="badge" style="background:var(--error-light);color:var(--error-text)">Diferenta: ${sign}${fmtNum(r.difference)} lei</span>
<small class="text-muted ms-2">Factura: ${fmtNum(r.invoice_total)} | Comanda: ${fmtNum(r.order_total)}</small>`;
}
reconEl.style.display = '';
} else if (reconEl) {
reconEl.style.display = 'none';
}
if (order.error_message) {
document.getElementById('detailError').textContent = order.error_message;
document.getElementById('detailError').style.display = '';