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
+67 -121
View File
@@ -1,68 +1,50 @@
{% extends "base.html" %}
{% block title %}Articoli - Mago4 Demo{% endblock %}
{% block page_title %}Articoli{% endblock %}
{% block window_tabs %}<a href="/products" class="window-tab active"><i class="material-icons">inventory_2</i> Articoli</a>{% endblock %}
{% block content %}
<div class="page-header">
<button class="btn btn-primary" onclick="openCreateProductModal()">
<i class="material-icons">add</i> Nuovo Articolo
</button>
{% if low_stock %}
<div class="alert alert-warning">
<i class="material-icons">warning</i>
{{ low_stock|length }} articolo/i sotto la soglia di riordino
</div>
{% endif %}
<div class="module-bar">
<div class="module-title">Articoli</div>
<div class="breadcrumb"><a href="/">Mago4</a><span class="sep">»</span><a href="/anagrafiche">Anagrafiche</a><span class="sep">»</span><span class="current">Articoli</span></div>
</div>
<div class="tab-strip">
<a href="/anagrafiche">Anagrafiche</a>
<a href="/customers">Clienti</a>
<a href="/suppliers">Fornitori</a>
<a href="/products" class="active">Articoli</a>
</div>
<div class="widget-card">
<div class="widget-header">
<h3 class="widget-title">Catalogo Articoli</h3>
</div>
<div class="widget-body">
<div class="doc-toolbar">
<button class="tb-btn" title="Nuovo" onclick="alert('Nuovo articolo (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>
</div>
<div class="content-pad">
{% if low_stock %}
<div class="alert alert-warning"><i class="material-icons">warning</i> {{ low_stock|length }} articolo/i sotto la scorta minima</div>
{% endif %}
<div class="panel">
<div class="panel-header"><h3><i class="material-icons">inventory_2</i> Catalogo Articoli</h3></div>
<table class="data-table">
<thead>
<tr>
<th>Codice</th>
<th>Descrizione</th>
<th>Categoria</th>
<th>Prezzo Unitario</th>
<th>Giacenza</th>
<th>Soglia Riordino</th>
<th>Fornitore</th>
<th>Azioni</th>
</tr>
</thead>
<thead><tr><th>Codice</th><th>Descrizione</th><th>Categoria</th><th class="text-center">UM</th><th class="text-right">Prezzo Vend.</th><th class="text-right">Costo</th><th class="text-center">IVA</th><th class="text-right">Giacenza</th><th></th></tr></thead>
<tbody>
{% for product in products %}
<tr class="{% if product.quantity_in_stock <= product.reorder_level %}low-stock{% endif %}">
<td><strong>{{ product.code }}</strong></td>
<td>{{ product.description }}</td>
<td>{{ product.category }}</td>
<td class="text-right">{{ "%.2f"|format(product.unit_price) }}</td>
<td class="text-right {% if product.quantity_in_stock <= product.reorder_level %}text-danger{% endif %}">
{{ product.quantity_in_stock }}
{% if product.quantity_in_stock <= product.reorder_level %}
<i class="material-icons small-icon">warning</i>
{% endif %}
</td>
<td class="text-right">{{ product.reorder_level }}</td>
<td>
{% if product.supplier_id %}
Fornitore #{{ product.supplier_id }}
{% else %}
{% endif %}
</td>
<td>
<button class="btn-small btn-info" onclick="viewProduct({{ product.id }})">
<i class="material-icons">visibility</i>
</button>
<button class="btn-small btn-warning" onclick="editProduct({{ product.id }})">
<i class="material-icons">edit</i>
</button>
{% for p in products %}
<tr class="{% if p.quantity_in_stock <= p.reorder_level %}low-stock{% endif %}">
<td class="text-bold mono">{{ p.code }}</td>
<td>{{ p.description }}</td>
<td>{{ p.category }}</td>
<td class="text-center">{{ p.uom }}</td>
<td class="text-right">€ {{ "%.2f"|format(p.unit_price) }}</td>
<td class="text-right text-mute">€ {{ "%.2f"|format(p.purchase_price) }}</td>
<td class="text-center">{{ "%.0f"|format(p.tax_rate) }}%</td>
<td class="text-right {% if p.quantity_in_stock <= p.reorder_level %}text-danger text-bold{% endif %}">
{{ p.quantity_in_stock }} {{ p.uom }}
{% if p.quantity_in_stock <= p.reorder_level %}<i class="material-icons" style="font-size:14px;vertical-align:middle;">warning</i>{% endif %}
</td>
<td class="text-center"><button class="btn-icon-sm act-view" onclick="viewProduct({{ p.id }})"><i class="material-icons">visibility</i></button></td>
</tr>
{% endfor %}
</tbody>
@@ -70,75 +52,39 @@
</div>
</div>
<div id="productModal" class="modal" onclick="closeModal(event)">
<div class="modal-content" onclick="event.stopPropagation()">
<div class="modal-header">
<h2 id="modalTitle">Dettagli Articolo</h2>
<button class="btn-close" onclick="closeModal()">
<i class="material-icons">close</i>
</button>
</div>
<div class="modal-body" id="modalBody">
</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 viewProduct(productId) {
fetch(`/api/products/${productId}`)
.then(r => r.json())
.then(data => {
const isLowStock = data.quantity_in_stock <= data.reorder_level;
document.getElementById('modalTitle').textContent = `Articolo: ${data.code}`;
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>Descrizione</label>
<span>${data.description}</span>
</div>
<div class="detail-item">
<label>Categoria</label>
<span>${data.category}</span>
</div>
<div class="detail-item">
<label>Prezzo Unitario</label>
<span>€ ${data.unit_price.toFixed(2)}</span>
</div>
<div class="detail-item">
<label>Giacenza Attuale</label>
<span class="${isLowStock ? 'text-danger' : ''}">
${data.quantity_in_stock} ${isLowStock ? '⚠️ SOTTOSORTA' : ''}
</span>
</div>
<div class="detail-item">
<label>Soglia Riordino</label>
<span>${data.reorder_level}</span>
</div>
<div class="detail-item">
<label>Fornitore</label>
<span>${data.supplier_id ? 'Fornitore #' + data.supplier_id : '—'}</span>
</div>
</div>
`;
document.getElementById('productModal').classList.add('show');
});
}
function editProduct(productId) {
alert('Modifica articolo: ' + productId + ' (da implementare)');
}
function openCreateProductModal() {
alert('Creazione nuovo articolo (da implementare)');
}
function closeModal(event) {
if (event && event.target.id !== 'productModal') return;
document.getElementById('productModal').classList.remove('show');
function viewProduct(id) {
fetch(`/api/products/${id}`).then(r=>r.json()).then(d=>{
const low = d.quantity_in_stock <= d.reorder_level;
openGenericModal('Articolo: ' + d.code, `
<div style="padding:16px">
<div class="form-section-title">Dati Principali</div>
<div class="form-grid-2">
${field('Codice', d.code)}${field('Descrizione', d.description)}
${field('Categoria', d.category)}${field('Unità di Misura', d.uom)}
</div>
<div class="form-section-title">Dati Commerciali</div>
<div class="form-grid-2">
${field('Prezzo di Vendita', '€ ' + d.unit_price.toFixed(2))}
${field('Costo di Acquisto', '€ ' + d.purchase_price.toFixed(2))}
${field('Aliquota IVA', d.tax_rate.toFixed(0) + '%')}
</div>
<div class="form-section-title">Dati Magazzino</div>
<div class="form-grid-2">
${field('Giacenza', '<span class="' + (low?'text-danger text-bold':'') + '">' + d.quantity_in_stock + ' ' + d.uom + (low?' ⚠ sottoscorta':'') + '</span>')}
${field('Scorta Minima', d.reorder_level + ' ' + d.uom)}
${field('Scorta Massima', d.max_stock + ' ' + d.uom)}
${field('Valore Giacenza', '€ ' + (d.quantity_in_stock * d.purchase_price).toFixed(2))}
</div>
</div>`);
});
}
</script>
{% endblock %}