diff --git a/index.html b/index.html
index dabb89c..03614f5 100644
--- a/index.html
+++ b/index.html
@@ -993,6 +993,22 @@
return div.innerHTML;
}
+ function normalizeName(name) {
+ return name
+ .toLowerCase()
+ .replace(/[^\w\s]/g, '') // Remove punctuation
+ .replace(/\s+/g, ' ') // Normalize whitespace
+ .trim();
+ }
+
+ function findDuplicates(name, excludeId = null) {
+ const normalized = normalizeName(name);
+ return inventory.filter(item => {
+ if (excludeId && item.id === excludeId) return false;
+ return normalizeName(item.name) === normalized;
+ });
+ }
+
function updateStats() {
const total = inventory.length;
const inStock = inventory.filter(i => !i.outOfStock).length;
@@ -1225,9 +1241,20 @@
showToast('Please enter an item name');
return;
}
-
+
+ // Check for duplicates when adding new items
+ if (!editingId) {
+ const duplicates = findDuplicates(name);
+ if (duplicates.length > 0) {
+ const dupNames = duplicates.map(d => d.name).join(', ');
+ if (!confirm(`Similar item exists: "${dupNames}"\n\nAdd anyway?`)) {
+ return;
+ }
+ }
+ }
+
showLoading();
-
+
try {
if (editingId) {
// Update existing