-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
164 lines (143 loc) · 9.06 KB
/
Copy pathindex.html
File metadata and controls
164 lines (143 loc) · 9.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pro Sync - Lite</title>
<!-- PWA Meta Tags -->
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#1a73e8">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="Pro Sync">
<link rel="apple-touch-icon" href="icon-192.png"> <!-- Make sure you have this icon -->
<!-- Firebase Lite SDKs -->
<script src="https://www.gstatic.com/firebasejs/9.17.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.17.1/firebase-firestore-compat.js"></script>
<style>
:root { --primary: #1a73e8; --wa-green: #25D366; --bg-color: #f8f9fa; }
body { font-family: -apple-system, system-ui, sans-serif; background: var(--bg-color); margin: 0; padding: 15px; color: #202124; -webkit-tap-highlight-color: transparent; }
.container { max-width: 480px; margin: auto; background: white; padding: 20px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); }
h2 { text-align: center; color: var(--primary); margin: 0 0 5px; letter-spacing: -0.5px; font-weight: 800; }
.subtitle { text-align: center; font-size: 13px; color: #5f6368; margin-bottom: 20px; display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; }
.live-dot { height: 8px; width: 8px; border-radius: 50%; display: inline-block; }
.status-online { background: #1e7e34; } .status-offline { background: #d93025; }
.pulse { animation: p 1.8s infinite; } @keyframes p { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.2); } }
.tenant-card { background: #fff; border: 1px solid #f1f3f4; padding: 15px; border-radius: 16px; margin-bottom: 12px; position: relative; box-shadow: 0 4px 12px rgba(0,0,0,0.05); transition: transform 0.1s; }
.tenant-card:active { transform: scale(0.98); }
.info b { font-size: 16px; display: block; color: #202124; }
.mobile-num { font-size: 13px; color: var(--primary); font-weight: 700; }
.details { font-size: 13px; color: #5f6368; margin-top: 4px; font-weight: 500; }
.sync-label { position: absolute; top: 15px; right: 15px; font-size: 9px; font-weight: 800; color: #1e7e34; background: #e6f4ea; padding: 2px 6px; border-radius: 4px; }
.btn-group { display: flex; gap: 8px; margin-top: 12px; }
.btn { flex: 1; padding: 12px; border: none; border-radius: 10px; font-weight: 700; cursor: pointer; font-size: 13px; color: white; transition: 0.2s; display: flex; align-items: center; justify-content: center; }
.btn-wa { background: var(--wa-green); } .btn-sms { background: var(--primary); }
.modal-overlay { display: none; position: fixed; top:0; left:0; width:100%; height:100%; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index:100; justify-content:center; align-items:center; }
.modal-box { background: white; padding: 24px; border-radius: 24px; width: 260px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-options { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.modal-btn { background: #f1f3f4; border: none; padding: 14px; border-radius: 12px; cursor: pointer; font-weight: 700; font-size: 14px; transition: 0.2s; }
.modal-btn:active { background: #e8eaed; }
.close-btn { font-size: 11px; color: #d93025; cursor: pointer; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
#loading { text-align: center; padding: 40px; font-weight: 600; color: #5f6368; }
</style>
</head>
<body onload="initApp()">
<div class="container">
<h2>Notification Sender</h2>
<div class="subtitle" id="syncStatus">
<span class="live-dot status-online pulse"></span> Connecting...
</div>
<div id="loading">⚡ Fast Syncing...</div>
<div id="msgList"></div>
</div>
<div id="msgModal" class="modal-overlay">
<div class="modal-box">
<h3 id="modalTitle" style="margin:0; font-weight: 800;"></h3>
<div class="modal-options">
<button class="modal-btn" onclick="sendSelected('bill')">📄 View Receipt</button>
<button class="modal-btn" onclick="sendSelected('reading_asm')">⚡ Meter Reading</button>
</div>
<div class="close-btn" onclick="closeModal()">Close</div>
</div>
</div>
<script>
// --- PWA Service Worker Registration ---
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js').catch(err => console.log('SW failed', err));
});
}
const firebaseConfig = {
apiKey: "AIzaSyBa0yOINCodJ4OhiK6l1PQyby72t6VGABM",
authDomain: "rentmastercloud.firebaseapp.com",
projectId: "rentmastercloud",
storageBucket: "rentmastercloud.firebasestorage.app",
messagingSenderId: "441950188457",
appId: "1:441950188457:web:29643fedca7df0913d8ab8"
};
firebase.initializeApp(firebaseConfig);
const fs = firebase.firestore();
let currentTenant = {}, currentBill = {}, currentMode = "";
function initApp() {
const msgList = document.getElementById('msgList');
const statusHeader = document.getElementById('syncStatus');
fs.collection("tenants").orderBy("name").onSnapshot(async (snap) => {
const isLive = !snap.metadata.fromCache;
document.getElementById('loading').style.display = "none";
msgList.innerHTML = "";
statusHeader.innerHTML = `<span class="live-dot ${isLive?'status-online pulse':'status-offline'}"></span> ${isLive?'Live Sync Active ✅':'Offline Mode ⚠️'}`;
const billPromises = snap.docs.map(doc => {
const tenant = doc.data();
return fs.collection("bills")
.where("tenantName", "==", tenant.name)
.orderBy("month", "desc").limit(1).get()
.then(bSnap => bSnap.empty ? null : {tenant, bill: bSnap.docs[0].data()});
});
const results = await Promise.all(billPromises);
results.forEach(res => { if(res) createCard(res.tenant, res.bill, isLive); });
});
}
function createCard(tenant, bill, isLive) {
const div = document.createElement('div');
div.className = 'tenant-card';
const dueColor = bill.remaining > 0 ? '#d93025' : '#1e7e34';
div.innerHTML = `
${isLive ? '<span class="sync-label">SYNCED</span>' : ''}
<div class="info">
<b>${tenant.name}</b>
<span class="mobile-num">📱 +91 ${tenant.mobile}</span>
<div class="details">${bill.month} | <span style="color:${dueColor}">${bill.remaining <= 0 ? 'PAID' : 'Due: ₹'+bill.remaining}</span></div>
</div>
<div class="btn-group">
<button class="btn btn-wa" onclick="openMsgSelector('wa','${tenant.name}','${tenant.mobile}','${bill.month}',${bill.remaining})">WhatsApp</button>
<button class="btn btn-sms" onclick="openMsgSelector('sms','${tenant.name}','${tenant.mobile}','${bill.month}',${bill.remaining})">SMS</button>
</div>`;
document.getElementById('msgList').appendChild(div);
}
function openMsgSelector(m, n, mo, mon, r) {
currentMode = m; currentTenant = {name:n, mobile:mo}; currentBill = {month:mon, remaining:r};
document.getElementById('modalTitle').innerText = n;
document.getElementById('msgModal').style.display = 'flex';
}
function closeModal() { document.getElementById('msgModal').style.display = 'none'; }
function sendSelected(type) {
const url = "https://adideb23.github.io/Khutabari";
let messageText = "";
if (type === 'bill') {
messageText = currentBill.remaining <= 0
? `Hello ${currentTenant.name}, your payment for ${currentBill.month} has been received. Thank you!\n\nView Receipt: ${url}`
: `Hello ${currentTenant.name}, your ${currentBill.month} rent is generated.\n\nTotal Due: ₹${currentBill.remaining}\n\nView Receipt: ${url}\n\nPlease pay soon. Thanks!`;
} else {
messageText = `নমস্কাৰ ${currentTenant.name},\n\nঅনুগ্ৰহ কৰি খুটাবাৰী পৰ্টেলত আপোনাৰ বৰ্তমানৰ মিটাৰ ৰিডিংটো দাখিল কৰক।\n\n${url}/\n\nধন্যবাদ!`;
}
const encodedMsg = encodeURIComponent(messageText);
const finalUrl = currentMode === 'wa'
? `https://wa.me/91${currentTenant.mobile}?text=${encodedMsg}`
: `sms:+91${currentTenant.mobile}?body=${encodedMsg}`;
window.open(finalUrl, '_blank');
closeModal();
}
</script>
</body>
</html>