20260316i: Low-stock Bring prompt after use

- API returns total_remaining, product_name, unit, default_qty after use
- isLowStock() detects when inventory is running low (pz<=2, conf<=1, weight/vol<=25% of default)
- After using a product, if low stock detected, shows prompt asking to add to Bring shopping list
- Works in main USE form, USE ALL, and recipe ingredient USE
- Prompt chains properly: low-stock then move-after-use (if applicable)
- Skips prompt when product is fully depleted (already auto-added to Bring)
This commit is contained in:
dadaloop82
2026-03-16 14:59:55 +00:00
parent 1d8fb55f58
commit b4b68d6579
4 changed files with 114 additions and 13 deletions
+18 -1
View File
@@ -764,7 +764,24 @@ function useFromInventory(PDO $db): void {
}
}
$response = ['success' => true, 'remaining' => $remaining, 'added_to_bring' => $addedToBring];
// Calculate total remaining across ALL locations
$stmt = $db->prepare("SELECT SUM(quantity) as total FROM inventory WHERE product_id = ? AND quantity > 0");
$stmt->execute([$productId]);
$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->execute([$productId]);
$prodInfo = $stmt->fetch();
$response = ['success' => true, 'remaining' => $remaining, 'added_to_bring' => $addedToBring,
'total_remaining' => $totalRemaining];
if ($prodInfo) {
$response['product_name'] = $prodInfo['name'];
$response['product_unit'] = $prodInfo['unit'];
$response['product_default_qty'] = (float)($prodInfo['default_quantity'] ?: 0);
$response['product_package_unit'] = $prodInfo['package_unit'] ?: '';
}
if ($openedId) $response['opened_id'] = $openedId;
echo json_encode($response);
}