From 7cc557d4dff824c5340a7b00f6b249e2d13cb0d5 Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Tue, 17 Mar 2026 13:55:30 +0000 Subject: [PATCH] 20260317c: Torta->Dolce, Bring specification with brand for product variants --- api/index.php | 14 ++++++++++---- assets/js/app.js | 14 ++++++++++---- data/dispensa.db | Bin 184320 -> 188416 bytes index.html | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/api/index.php b/api/index.php index 20923d6..0c2ea96 100644 --- a/api/index.php +++ b/api/index.php @@ -742,10 +742,12 @@ function useFromInventory(PDO $db): void { // Already on the list, skip adding $addedToBring = false; } else { + // Build specification from brand + $spec = $product['brand'] ? $product['brand'] : ''; $body = http_build_query([ 'uuid' => $listUUID, 'purchase' => $bringName, - 'specification' => '', + 'specification' => $spec, ]); $result = bringRequest('PUT', "https://api.getbring.com/rest/v2/bringlists/{$listUUID}", $body); $addedToBring = ($result !== null); @@ -770,7 +772,7 @@ function useFromInventory(PDO $db): void { $totalRemaining = round((float)($stmt->fetchColumn() ?: 0), 6); // Get product info for low-stock prompt - $stmt = $db->prepare("SELECT name, unit, default_quantity, package_unit FROM products WHERE id = ?"); + $stmt = $db->prepare("SELECT name, brand, unit, default_quantity, package_unit FROM products WHERE id = ?"); $stmt->execute([$productId]); $prodInfo = $stmt->fetch(); @@ -778,6 +780,7 @@ function useFromInventory(PDO $db): void { 'total_remaining' => $totalRemaining]; if ($prodInfo) { $response['product_name'] = $prodInfo['name']; + $response['product_brand'] = $prodInfo['brand'] ?: ''; $response['product_unit'] = $prodInfo['unit']; $response['product_default_qty'] = (float)($prodInfo['default_quantity'] ?: 0); $response['product_package_unit'] = $prodInfo['package_unit'] ?: ''; @@ -1356,7 +1359,9 @@ function generateRecipe(PDO $db): void { $mealLabels = [ 'colazione' => 'colazione (mattina)', 'pranzo' => 'pranzo (mezzogiorno)', - 'cena' => 'cena (sera)' + 'cena' => 'cena (sera)', + 'dolce' => 'dolce/dessert', + 'succo' => 'succo di frutta/bevanda' ]; $mealLabel = $mealLabels[$mealType] ?? $mealType; @@ -2072,10 +2077,11 @@ function bringAddItems(): void { continue; } + $spec = $item['specification'] ?? ''; $body = http_build_query([ 'uuid' => $listUUID, 'purchase' => $bringName, - 'specification' => '', + 'specification' => $spec, ]); $result = bringRequest('PUT', "https://api.getbring.com/rest/v2/bringlists/{$listUUID}", $body); diff --git a/assets/js/app.js b/assets/js/app.js index 2fa90d3..1db105c 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -3497,6 +3497,7 @@ function isLowStock(totalRemaining, unit, defaultQty) { function showLowStockBringPrompt(result, afterCallback) { const name = result.product_name || currentProduct?.name || ''; + const brand = result.product_brand || currentProduct?.brand || ''; const unit = result.product_unit || currentProduct?.unit || 'pz'; const defaultQty = result.product_default_qty || parseFloat(currentProduct?.default_quantity) || 0; const totalRemaining = result.total_remaining; @@ -3516,16 +3517,19 @@ function showLowStockBringPrompt(result, afterCallback) { remainLabel = `${Number.isInteger(totalRemaining) ? totalRemaining : totalRemaining.toFixed(1)} ${unitLabels[unit] || unit}`; } - // Store callback for after user responds + // Build specification from brand for Bring + const spec = brand || ''; window._lowStockAfterCallback = afterCallback; + window._lowStockSpec = spec; + const brandNote = brand ? ` (${escapeHtml(brand)})` : ''; document.getElementById('modal-content').innerHTML = `
-

${escapeHtml(name)} sta per finire — rimangono solo ${remainLabel}.

+

${escapeHtml(name)}${brandNote} sta per finire — rimangono solo ${remainLabel}.

Vuoi aggiungerlo alla lista della spesa?

- +