Skip to content

Commit 1b3ad0d

Browse files
committed
Remove inventory movement from Today, add notification debug logging
1 parent d25feb0 commit 1b3ad0d

3 files changed

Lines changed: 13 additions & 20 deletions

File tree

www/js/firebase/firestore-service.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,19 +961,24 @@ const FirebaseService = {
961961
});
962962
unsubscribeFunctions.push(unsubItemFrequency);
963963

964+
console.log('Setting up notifications listener for user:', AppState.currentUser.uid);
965+
964966
const unsubNotifications = getDb().collection(col('notifications'))
965967
.where('userId', '==', AppState.currentUser.uid)
966968
.where('read', '==', false)
967969
.orderBy('timestamp', 'desc')
968970
.limit(10)
969971
.onSnapshot(snapshot => {
972+
console.log('Notifications snapshot received, changes:', snapshot.docChanges().length);
970973
snapshot.docChanges().forEach(change => {
974+
console.log('Notification change type:', change.type, change.doc.data());
971975
if (change.type === 'added') {
972976
const notification = change.doc.data();
973977
// Show toast for rate change notifications
974978
if (notification.type === 'rate_change') {
975979
const itemName = notification.itemHindiName || notification.itemName;
976980
const message = `${itemName} ${notification.rateTypeLabel} rate: ₹${notification.oldRate} → ₹${notification.newRate} (by ${notification.changedBy})`;
981+
console.log('Showing rate change toast:', message);
977982
UIManager.showToast(message, 5000);
978983

979984
// Mark as read after showing
@@ -985,6 +990,8 @@ const FirebaseService = {
985990
console.error('Notifications listener error:', error);
986991
});
987992
unsubscribeFunctions.push(unsubNotifications);
993+
} else {
994+
console.warn('No currentUser.uid, skipping notifications listener');
988995
}
989996
},
990997

@@ -1079,17 +1086,22 @@ const FirebaseService = {
10791086
read: false
10801087
};
10811088

1089+
console.log(`Notifying ${userIds.length} users about rate change, excluding current user: ${AppState.currentUser?.uid}`);
1090+
10821091
// Notify all relevant users except the one who made the change
1092+
let notifiedCount = 0;
10831093
for (const userId of userIds) {
10841094
if (userId !== AppState.currentUser?.uid) {
10851095
await getDb().collection(col('notifications')).add({
10861096
...notification,
10871097
userId: userId
10881098
});
1099+
notifiedCount++;
1100+
console.log(`Notification saved for user: ${userId}`);
10891101
}
10901102
}
10911103

1092-
console.log(`Rate change notification sent: ${item.name} ${rateType} rate: ₹${oldRate} → ₹${newRate}`);
1104+
console.log(`Rate change notification sent to ${notifiedCount} users: ${item.name} ${rateType} rate: ₹${oldRate} → ₹${newRate}`);
10931105
} catch (error) {
10941106
console.error('Error notifying rate change:', error);
10951107
}

www/js/modules/day.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ export const DayManager = {
198198
this.updateElement('todayPersonalExpenses', formatCurrency(totalPersonalExpenses));
199199
this.updateElement('todayPersonalExpenseCount', `${personalExpenses.length} entries`);
200200

201-
// Quantity metrics
202-
this.updateElement('todayQtyPurchased', `${qtyPurchased.toFixed(1)} kg`);
203-
this.updateElement('todayQtySold', `${qtySold.toFixed(1)} kg`);
204-
205201
// Total In and Total Out for hero card
206202
this.updateElement('todayTotalIn', formatCurrency(cashReceived + onlineReceived));
207203
this.updateElement('todayTotalOut', formatCurrency(cashPaid + onlinePaid + totalExpenses));

www/templates/day.html

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,6 @@ <h3 class="section-title">📋 Due Summary</h3>
113113
</div>
114114
</div>
115115

116-
<!-- 5. INVENTORY MOVEMENT -->
117-
<div class="modern-card" style="background: #f8fafc; border: 1px dashed #cbd5e1;">
118-
<h3 class="section-title" style="color: #64748b;">📦 Inventory Movement</h3>
119-
<div class="stats-grid stats-grid-2" style="margin-bottom: 0;">
120-
<div class="stat-card" style="background: #ecfdf5; border: 1px solid #a7f3d0;">
121-
<div class="stat-label" style="color: #065f46;">Qty In</div>
122-
<div class="stat-value-sm stat-value-success" id="todayQtyPurchased">0 kg</div>
123-
</div>
124-
<div class="stat-card" style="background: #eff6ff; border: 1px solid #bfdbfe;">
125-
<div class="stat-label" style="color: #1e40af;">Qty Out</div>
126-
<div class="stat-value-sm stat-value-info" id="todayQtySold">0 kg</div>
127-
</div>
128-
</div>
129-
</div>
130-
131116
<!-- 6. ITEM DETAILS (Scrollable) -->
132117
<div class="modern-card">
133118
<h3 class="section-title">🛒 Purchase Details</h3>

0 commit comments

Comments
 (0)