Restyle UI to match Mago4 and add invoicing, warehouse, scadenzario

Rework the demo into a faithful Mago4 look-and-feel and expand it with
core ERP modules modelled on the real Mago4 database schema.

UI (ispirata a Mago4):
- Blue header with logo/search/operation date, desktop-style window tabs
- White sidebar with coloured module icons (Anagrafiche, Vendite, Acquisti,
  Amministrazione, Logistica)
- Card-based module landing pages with breadcrumb + tab strip
- Document detail forms with left tabs, line grid and totals box

Fatturazione (InvoiceMng / MA_SaleDoc):
- Document types (Fattura Immediata, DDT, Nota di Credito, ProForma)
- Lines with discount/IVA, automatic taxable/tax/total computation
- Document states (draft -> printed -> issued / posted_to_inventory)

Magazzino (Inventory / MA_InventoryEntries + MA_InventoryReasons):
- Inventory movements with load/unload reasons (DebitCreditSign)
- Posting a movement actually updates item balances
- Causali and stock valuation pages

Amministrazione / Scadenzario (AP_AR / MA_PyblsRcvbls):
- Open items (receivables/payables) with due date, method, state
- Settle action closes the item and recomputes the cash forecast

Dashboard riprogettata (focus su scadenze e to-do):
- Overdue alert banner, KPI for overdue payables/receivables
- Upcoming deadlines table, prioritised "Cose da fare" action list
- 30-day cash-flow forecast and customer credit-limit check

Adds REST endpoints for invoices, movements, schedules and dashboard data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 11:47:32 +02:00
co-authored by Claude Sonnet 4.6
parent 8a9fb5085a
commit b6b6759b9a
26 changed files with 2900 additions and 2125 deletions
+60 -111
View File
@@ -1,53 +1,46 @@
{% extends "base.html" %}
{% block title %}Clienti - Mago4 Demo{% endblock %}
{% block page_title %}Clienti{% endblock %}
{% block window_tabs %}<a href="/customers" class="window-tab active"><i class="material-icons">people</i> Clienti</a>{% endblock %}
{% block content %}
<div class="page-header">
<button class="btn btn-primary" onclick="openCreateCustomerModal()">
<i class="material-icons">add</i> Nuovo Cliente
</button>
<div class="module-bar">
<div class="module-title">Clienti</div>
<div class="breadcrumb"><a href="/">Mago4</a><span class="sep">»</span><a href="/anagrafiche">Anagrafiche</a><span class="sep">»</span><span class="current">Clienti</span></div>
</div>
<div class="tab-strip">
<a href="/anagrafiche">Anagrafiche</a>
<a href="/customers" class="active">Clienti</a>
<a href="/suppliers">Fornitori</a>
<a href="/products">Articoli</a>
</div>
<div class="widget-card">
<div class="widget-header">
<h3 class="widget-title">Elenco Clienti</h3>
</div>
<div class="widget-body">
<div class="doc-toolbar">
<button class="tb-btn" title="Nuovo" onclick="alert('Nuovo cliente (demo)')"><i class="material-icons">add_box</i></button>
<button class="tb-btn" title="Cerca"><i class="material-icons">search</i></button>
<div class="tb-sep"></div>
<button class="tb-btn" title="Stampa"><i class="material-icons">print</i></button>
<button class="tb-btn" title="Esporta"><i class="material-icons">file_download</i></button>
</div>
<div class="content-pad">
<div class="panel">
<div class="panel-header"><h3><i class="material-icons">people</i> Elenco Clienti</h3></div>
<table class="data-table">
<thead>
<tr>
<th>Codice</th>
<th>Ragione Sociale</th>
<th>Città</th>
<th>Paese</th>
<th>Telefono</th>
<th>Limite Credito</th>
<th>Saldo</th>
<th>Azioni</th>
</tr>
<tr><th>Codice</th><th>Ragione Sociale</th><th>Partita IVA</th><th>Città</th><th>Paese</th><th>Pagamento</th><th class="text-right">Fido</th><th class="text-right">Saldo</th><th></th></tr>
</thead>
<tbody>
{% for customer in customers %}
{% for c in customers %}
<tr>
<td><strong>{{ customer.code }}</strong></td>
<td>{{ customer.name }}</td>
<td>{{ customer.city }}</td>
<td>{{ customer.country }}</td>
<td>{{ customer.phone }}</td>
<td class="text-right">{{ "%.2f"|format(customer.credit_limit) }}</td>
<td class="text-right {% if customer.balance > 0 %}text-danger{% endif %}">
€ {{ "%.2f"|format(customer.balance) }}
</td>
<td>
<button class="btn-small btn-info" onclick="viewCustomer({{ customer.id }})">
<i class="material-icons">visibility</i>
</button>
<button class="btn-small btn-warning" onclick="editCustomer({{ customer.id }})">
<i class="material-icons">edit</i>
</button>
</td>
<td class="text-bold mono">{{ c.code }}</td>
<td>{{ c.name }}</td>
<td class="mono">{{ c.vat_number or '—' }}</td>
<td>{{ c.city }}</td>
<td>{{ c.country }}</td>
<td>{{ c.payment_terms }}</td>
<td class="text-right">€ {{ "%.0f"|format(c.credit_limit) }}</td>
<td class="text-right {% if c.balance > 0 %}text-danger{% endif %}">€ {{ "%.2f"|format(c.balance) }}</td>
<td class="text-center"><button class="btn-icon-sm act-view" onclick="viewCustomer({{ c.id }})"><i class="material-icons">visibility</i></button></td>
</tr>
{% endfor %}
</tbody>
@@ -55,82 +48,38 @@
</div>
</div>
<!-- Modal Detail -->
<div id="customerModal" class="modal" onclick="closeModal(event)">
<div class="modal-content" onclick="event.stopPropagation()">
<div class="modal-header">
<h2 id="modalTitle">Dettagli Cliente</h2>
<button class="btn-close" onclick="closeModal()">
<i class="material-icons">close</i>
</button>
</div>
<div class="modal-body" id="modalBody">
<!-- Content loaded via JS -->
</div>
<div id="genericModal" class="modal" onclick="if(event.target.id==='genericModal')closeGenericModal()">
<div class="modal-content">
<div class="modal-header"><h2 id="gmTitle">Dettagli</h2><button class="modal-close" onclick="closeGenericModal()"><i class="material-icons">close</i></button></div>
<div class="modal-body" id="gmBody"></div>
</div>
</div>
<script>
function viewCustomer(customerId) {
fetch(`/api/customers/${customerId}`)
.then(r => r.json())
.then(data => {
document.getElementById('modalTitle').textContent = `Cliente: ${data.name}`;
document.getElementById('modalBody').innerHTML = `
<div class="detail-grid">
<div class="detail-item">
<label>Codice</label>
<span>${data.code}</span>
</div>
<div class="detail-item">
<label>Ragione Sociale</label>
<span>${data.name}</span>
</div>
<div class="detail-item">
<label>Email</label>
<span>${data.email}</span>
</div>
<div class="detail-item">
<label>Telefono</label>
<span>${data.phone}</span>
</div>
<div class="detail-item">
<label>Indirizzo</label>
<span>${data.address}</span>
</div>
<div class="detail-item">
<label>Città</label>
<span>${data.city}</span>
</div>
<div class="detail-item">
<label>Paese</label>
<span>${data.country}</span>
</div>
<div class="detail-item">
<label>Limite Credito</label>
<span>€ ${data.credit_limit.toFixed(2)}</span>
</div>
<div class="detail-item">
<label>Saldo</label>
<span class="${data.balance > 0 ? 'text-danger' : ''}">${data.balance > 0 ? '€ ' : ''}${Math.abs(data.balance).toFixed(2)}</span>
</div>
</div>
`;
document.getElementById('customerModal').classList.add('show');
});
}
function editCustomer(customerId) {
alert('Modifica cliente: ' + customerId + ' (da implementare)');
}
function openCreateCustomerModal() {
alert('Creazione nuovo cliente (da implementare)');
}
function closeModal(event) {
if (event && event.target.id !== 'customerModal') return;
document.getElementById('customerModal').classList.remove('show');
function viewCustomer(id) {
fetch(`/api/customers/${id}`).then(r=>r.json()).then(d=>{
document.getElementById('gmTitle').textContent = 'Cliente: ' + d.name;
document.getElementById('gmBody').innerHTML = `
<div style="padding:16px">
<div class="form-section-title">Dati Principali</div>
<div class="form-grid-2">
${field('Codice', d.code)}${field('Ragione Sociale', d.name)}
${field('Partita IVA', d.vat_number || '—')}${field('Codice Fiscale', d.fiscal_code || '—')}
${field('Email', d.email)}${field('Telefono', d.phone)}
</div>
<div class="form-section-title">Indirizzo</div>
<div class="form-grid-2">
${field('Indirizzo', d.address)}${field('Città', d.city)}
${field('Paese', d.country)}${field('Pagamento', d.payment_terms)}
</div>
<div class="form-section-title">Dati Commerciali</div>
<div class="form-grid-2">
${field('Limite Credito', '€ ' + d.credit_limit.toFixed(2))}
${field('Saldo', '€ ' + d.balance.toFixed(2))}
</div>
</div>`;
document.getElementById('genericModal').classList.add('show');
});
}
</script>
{% endblock %}