20260317c: Torta->Dolce, Bring specification with brand for product variants

This commit is contained in:
dadaloop82
2026-03-17 13:55:30 +00:00
parent d1df6a6862
commit 7cc557d4df
4 changed files with 22 additions and 10 deletions
+10 -4
View File
@@ -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);
+10 -4
View File
@@ -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 = `
<div class="modal-header">
<h3> Sta per finire!</h3>
<button class="modal-close" onclick="closeLowStockPrompt()"></button>
</div>
<div style="padding:0 16px 16px">
<p style="margin-bottom:12px"><strong>${escapeHtml(name)}</strong> sta per finire rimangono solo <strong>${remainLabel}</strong>.</p>
<p style="margin-bottom:12px"><strong>${escapeHtml(name)}</strong>${brandNote} sta per finire rimangono solo <strong>${remainLabel}</strong>.</p>
<p style="margin-bottom:16px">Vuoi aggiungerlo alla lista della spesa?</p>
<button type="button" class="btn btn-large btn-success full-width" onclick="addLowStockToBring('${escapeHtml(name).replace(/'/g, "\\'")}')">
🛒 , aggiungi a Bring!
@@ -3541,7 +3545,9 @@ function showLowStockBringPrompt(result, afterCallback) {
async function addLowStockToBring(productName) {
closeModal();
try {
const payload = { items: [{ name: productName }] };
const spec = window._lowStockSpec || '';
window._lowStockSpec = null;
const payload = { items: [{ name: productName, specification: spec }] };
if (shoppingListUUID) payload.listUUID = shoppingListUUID;
const data = await api('bring_add', {}, 'POST', payload);
if (data.success && data.added > 0) {
@@ -4835,7 +4841,7 @@ const MEAL_TYPES = [
{ id: 'pranzo', icon: '🍽️', label: 'Pranzo', from: 11, to: 14 },
{ id: 'merenda', icon: '🍪', label: 'Merenda', from: 14, to: 17 },
{ id: 'cena', icon: '🌙', label: 'Cena', from: 17, to: 6 },
{ id: 'torta', icon: '🎂', label: 'Torta', from: -1, to: -1 },
{ id: 'dolce', icon: '🍰', label: 'Dolce', from: -1, to: -1 },
{ id: 'succo', icon: '🧃', label: 'Succo di Frutta', from: -1, to: -1 },
];
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -9,7 +9,7 @@
<title>Dispensa Manager</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🏠</text></svg>">
<link rel="stylesheet" href="assets/css/style.css?v=20260317b">
<link rel="stylesheet" href="assets/css/style.css?v=20260317c">
<!-- QuaggaJS for barcode scanning -->
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2@1.8.4/dist/quagga.min.js"></script>
</head>
@@ -911,6 +911,6 @@
</div>
</div>
<script src="assets/js/app.js?v=20260317b"></script>
<script src="assets/js/app.js?v=20260317c"></script>
</body>
</html>