Sposta prodotto dopo l'uso + fix prodotti aperti
- Dopo aver usato un prodotto, se rimane quantità mostra modal con opzione di spostarlo in un'altra posizione (es. dispensa→frigo dopo apertura) - La scadenza viene ricalcolata per la nuova posizione - Fix marmellata: default_quantity era 0 → non appariva tra prodotti aperti - Auto-set default_quantity al primo add per prodotti g/ml/kg/l senza pkg size - Versione: 20260316b
This commit is contained in:
@@ -501,6 +501,15 @@ function addToInventory(PDO $db): void {
|
||||
if ($unit) {
|
||||
$stmt = $db->prepare("UPDATE products SET unit = ?, default_quantity = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?");
|
||||
$stmt->execute([$unit, $quantity, $productId]);
|
||||
} else {
|
||||
// Auto-set default_quantity if product has none (first add sets package size)
|
||||
$stmt = $db->prepare("SELECT default_quantity, unit FROM products WHERE id = ?");
|
||||
$stmt->execute([$productId]);
|
||||
$prod = $stmt->fetch();
|
||||
if ($prod && (float)($prod['default_quantity'] ?? 0) == 0 && !in_array($prod['unit'], ['pz', 'conf'])) {
|
||||
$stmt = $db->prepare("UPDATE products SET default_quantity = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?");
|
||||
$stmt->execute([$quantity, $productId]);
|
||||
}
|
||||
}
|
||||
|
||||
// Update package info if conf
|
||||
|
||||
Reference in New Issue
Block a user