📒 Digital Khata — Code Review & Enhanced Version ✅ What's Already Great Area Details…
- User
📒 Digital Khata — Code Review & Enhanced Version
✅ What's Already Great
Area Details Structure Clean single-file architecture, well-organized sections Security escapeHTML()prevents XSS — excellent practicePersistence localStoragekeeps data across sessionsValidation Guards against negative/over-payments i18n Full Hindi UI matches the target audience perfectly Responsive Media query handles mobile gracefully
⚠️ Issues & Missing Features
- No data backup — clearing browser data = losing all records
- No dashboard summary — shop owner can't see total pending at a glance
- No edit capability — a typo in a name is permanent
- No phone validation — accepts
"abc"as a phone number - No duplicate detection — same customer can be added 10 times
- No WhatsApp reminder — the most natural action for Indian shopkeepers
- No print/export — needed for disputes or record-keeping
- No sorting — list grows unmanageable over time
🚀 Enhanced Version
<!DOCTYPE html> <html lang="hi"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Digital Khata</title> <style> * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: 'Segoe UI', Arial, sans-serif; background: #f0f4f8; color: #1f2937; min-height: 100vh; } header { background: linear-gradient(135deg, #166534, #15803d); color: white; padding: 24px 20px; text-align: center; box-shadow: 0 4px 20px rgba(22, 101, 52, 0.3); } header h1 { font-size: 28px; margin-bottom: 4px; } header p { opacity: 0.9; font-size: 14px; } .container { max-width: 1000px; margin: 20px auto; padding: 0 15px; } /* ── Dashboard ── */ .dashboard { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; } .stat-card { background: white; border-radius: 14px; padding: 18px; text-align: center; box-shadow: 0 2px 10px rgba(0,0,0,0.06); transition: transform 0.2s; } .stat-card:hover { transform: translateY(-2px); } .stat-card .number { font-size: 26px; font-weight: 800; display: block; margin-bottom: 4px; } .stat-card .label { font-size: 13px; color: #6b7280; } .stat-green .number { color: #166534; } .stat-red .number { color: #dc2626; } .stat-blue .number { color: #2563eb; } /* ── Cards ── */ .card { background: white; padding: 22px; border-radius: 14px; margin-bottom: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.07); } .card h2 { margin-bottom: 16px; font-size: 20px; } .form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; } input, select { width: 100%; padding: 12px 14px; border: 2px solid #e5e7eb; border-radius: 10px; font-size: 16px; transition: border-color 0.2s; outline: none; } input:focus, select:focus { border-color: #166534; } .error-input { border-color: #dc2626 !important; animation: shake 0.4s; } @keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } } /* ── Buttons ── */ button { border: none; padding: 11px 16px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; margin: 3px; transition: opacity 0.2s, transform 0.1s; } button:hover { opacity: 0.88; } button:active { transform: scale(0.97); } .add-btn { background: #166534; color: white; } .payment-btn { background: #2563eb; color: white; } .delete-btn { background: #dc2626; color: white; } .clear-btn { background: #16a34a; color: white; } .edit-btn { background: #d97706; color: white; } .wa-btn { background: #25d366; color: white; } .export-btn { background: #7c3aed; color: white; } .import-btn { background: #0891b2; color: white; } .sort-btn { background: #64748b; color: white; } .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; } .toolbar input { flex: 1; min-width: 200px; } .toolbar select { width: auto; min-width: 160px; } /* ── Customer Card ── */ .customer { border: 2px solid #e5e7eb; border-radius: 14px; padding: 18px; margin-bottom: 14px; transition: border-color 0.2s, box-shadow 0.2s; } .customer:hover { border-color: #166534; box-shadow: 0 4px 16px rgba(22,101,52,0.1); } .customer.cleared { border-color: #bbf7d0; background: #f0fdf4; } .customer-header { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; } .customer h3 { font-size: 18px; } .amounts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; } .amount-box { background: #f9fafb; padding: 10px; border-radius: 8px; text-align: center; } .amount-box .val { font-size: 18px; font-weight: 700; display: block; } .amount-box .lbl { font-size: 12px; color: #6b7280; } .status { display: inline-block; padding: 5px 12px; border-radius: 20px; font-weight: 700; font-size: 13px; } .clear { background: #dcfce7; color: #166534; } .pending { background: #fee2e2; color: #991b1b; } .history { margin-top: 12px; padding: 12px; background: #f9fafb; border-radius: 10px; font-size: 14px; max-height: 150px; overflow-y: auto; } .history div { padding: 4px 0; border-bottom: 1px dashed #e5e7eb; } .history div:last-child { border-bottom: none; } .actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 4px; } .empty { text-align: center; color: #9ca3af; padding: 40px 20px; font-size: 16px; } /* ── Modal ── */ .modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center; padding: 20px; } .modal-overlay.active { display: flex; } .modal { background: white; border-radius: 16px; padding: 28px; max-width: 440px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,0.2); animation: modalIn 0.25s ease; } @keyframes modalIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } } .modal h3 { margin-bottom: 16px; } .modal input { margin-bottom: 12px; } .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; } .cancel-btn { background: #e5e7eb; color: #374151; } /* ── Toast ── */ .toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px); background: #1f2937; color: white; padding: 14px 28px; border-radius: 12px; font-size: 15px; font-weight: 600; z-index: 2000; transition: transform 0.35s ease; box-shadow: 0 8px 30px rgba(0,0,0,0.25); } .toast.show { transform: translateX(-50%) translateY(0); } /* ── Responsive ── */ @media (max-width: 650px) { .form-grid { grid-template-columns: 1fr; } .amounts { grid-template-columns: 1fr; } .dashboard { grid-template-columns: 1fr; } .customer-header { flex-direction: column; align-items: flex-start; } header h1 { font-size: 22px; } } @media print { header, .card:first-of-type, .toolbar, .actions, .toast { display: none !important; } .customer { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; } } </style> </head> <body> <header> <h1>📒 Digital Khata</h1> <p>ग्राहकों का हिसाब आसानी से रखें</p> </header> <div class="container"> <!-- Dashboard --> <div class="dashboard"> <div class="stat-card stat-blue"> <span class="number" id="statTotal">0</span> <span class="label">कुल ग्राहक</span> </div> <div class="stat-card stat-red"> <span class="number" id="statPending">₹0</span> <span class="label">कुल बकाया</span> </div> <div class="stat-card stat-green"> <span class="number" id="statCleared">0</span> <span class="label">क्लियर खाते</span> </div> </div> <!-- Add Customer --> <div class="card"> <h2>➕ नया ग्राहक जोड़ें</h2> <div class="form-grid"> <input id="name" type="text" placeholder="ग्राहक का नाम *"> <input id="phone" type="tel" placeholder="मोबाइल नंबर"> <input id="total" type="number" placeholder="कुल उधार ₹ *" min="1"> <input id="paid" type="number" placeholder="जमा रकम ₹" min="0"> </div> <br> <button class="add-btn" onclick="addCustomer()">💾 ग्राहक सेव करें</button> </div> <!-- Search & List --> <div class="card"> <h2>📋 ग्राहक सूची</h2> <div class="toolbar"> <input id="search" type="text" placeholder="🔎 नाम या नंबर से खोजें..." oninput="displayCustomers()"> <select id="sortSelect" onchange="displayCustomers()"> <option value="newest">🕐 नए पहले</option> <option value="oldest">🕐 पुराने पहले</option> <option value="highest">💰 सबसे ज़्यादा बकाया</option> <option value="lowest">💰 सबसे कम बकाया</option> <option value="name">🔤 नाम (A-Z)</option> </select> <select id="filterSelect" onchange="displayCustomers()"> <option value="all">सभी</option> <option value="pending">🔴 बकाया</option> <option value="cleared">✅ क्लियर</option> </select> </div> <div style="display:flex; flex-wrap:wrap; gap:6px; margin-bottom:14px;"> <button class="export-btn" onclick="exportData()">📤 बैकअप</button> <button class="import-btn" onclick="document.getElementById('importFile').click()">📥 रिस्टोर</button> <input type="file" id="importFile" accept=".json" style="display:none" onchange="importData(event)"> <button class="sort-btn" onclick="window.print()">🖨️ प्रिंट</button> </div> <div id="customerList"></div> </div> </div> <!-- Edit Modal --> <div class="modal-overlay" id="editModal"> <div class="modal"> <h3>✏️ ग्राहक संपादित करें</h3> <input id="editName" type="text" placeholder="नाम"> <input id="editPhone" type="tel" placeholder="मोबाइल नंबर"> <input id="editTotal" type="number" placeholder="कुल रकम" min="1"> <input type="hidden" id="editId"> <div class="modal-actions"> <button class="cancel-btn" onclick="closeModal()">रद्द करें</button> <button class="add-btn" onclick="saveEdit()">सेव करें</button> </div> </div> </div> <!-- Payment Modal --> <div class="modal-overlay" id="paymentModal"> <div class="modal"> <h3>💵 Payment जमा करें</h3> <p id="paymentInfo" style="margin-bottom:12px; color:#6b7280;"></p> <input id="paymentAmount" type="number" placeholder="जमा रकम ₹" min="1"> <div class="modal-actions"> <button class="cancel-btn" onclick="closePaymentModal()">रद्द करें</button> <button class="payment-btn" onclick="confirmPayment()">जमा करें</button> </div> </div> </div> <!-- Toast --> <div class="toast" id="toast"></div> <script> let customers = JSON.parse(localStorage.getItem("digitalKhata")) || []; let currentPaymentId = null; /* ── Helpers ── */ function saveData() { localStorage.setItem("digitalKhata", JSON.stringify(customers)); } function escapeHTML(text) { const div = document.createElement("div"); div.textContent = text; return div.innerHTML; } function fmt(n) { return "₹" + Math.max(n, 0).toLocaleString("en-IN"); } function toast(msg) { const t = document.getElementById("toast"); t.textContent = msg; t.classList.add("show"); setTimeout(() => t.classList.remove("show"), 2800); } function flashError(id) { const el = document.getElementById(id); el.classList.add("error-input"); setTimeout(() => el.classList.remove("error-input"), 600); el.focus(); } function isValidPhone(phone) { if (!phone) return true; // optional return /^\d{10}$/.test(phone.replace(/[\s\-+]/g, "")); } /* ── Dashboard ── */ function updateDashboard() { const totalCustomers = customers.length; const totalPending = customers.reduce((s, c) => s + Math.max(c.total - c.paid, 0), 0); const clearedCount = customers.filter(c => c.paid >= c.total).length; document.getElementById("statTotal").textContent = totalCustomers; document.getElementById("statPending").textContent = fmt(totalPending); document.getElementById("statCleared").textContent = clearedCount; } /* ── CRUD ── */ function addCustomer() { const name = document.getElementById("name").value.trim(); const phone = document.getElementById("phone").value.trim(); const total = Number(document.getElementById("total").value); const paid = Number(document.getElementById("paid").value) || 0; if (!name) { flashError("name"); return toast("⚠️ ग्राहक का नाम लिखें"); } if (!total || total <= 0) { flashError("total"); return toast("⚠️ कुल रकम सही लिखें"); } if (paid > total) { flashError("paid"); return toast("⚠️ जमा रकम कुल से ज़्यादा नहीं"); } if (!isValidPhone(phone)) { flashError("phone"); return toast("⚠️ 10 अंकों का मोबाइल नंबर डालें"); } // Duplicate check const dup = customers.find( c => c.name.toLowerCase() === name.toLowerCase() && c.phone && phone && c.phone.replace(/\D/g, "") === phone.replace(/\D/g, "") ); if (dup) return toast("⚠️ यह ग्राहक पहले से मौजूद है"); const customer = { id: Date.now(), name, phone, total, paid, history: [] }; if (paid > 0) { customer.history.push({ amount: paid, date: new Date().toLocaleString("hi-IN"), note: "शुरुआती जमा" }); } customers.push(customer); saveData(); ["name", "phone", "total", "paid"].forEach( id => document.getElementById(id).value = "" ); displayCustomers(); toast("✅ ग्राहक सेव हो गया!"); } function openPaymentModal(id) { const c = customers.find(c => c.id === id); if (!c) return; const remaining = c.total - c.paid; if (remaining <= 0) return toast("✅ खाता पहले ही क्लियर है"); currentPaymentId = id; document.getElementById("paymentInfo").textContent = `${c.name} — बाकी रकम: ${fmt(remaining)}`; document.getElementById("paymentAmount").value = ""; document.getElementById("paymentModal").classList.add("active"); document.getElementById("paymentAmount").focus(); } function closePaymentModal() { document.getElementById("paymentModal").classList.remove("active"); currentPaymentId = null; } function confirmPayment() { if (!currentPaymentId) return; const c = customers.find(c => c.id === currentPaymentId); if (!c) return; const payment = Number(document.getElementById("paymentAmount").value); const remaining = c.total - c.paid; if (!payment || payment <= 0) return toast("⚠️ सही रकम डालें"); if (payment > remaining) return toast(`⚠️ रकम ${fmt(remaining)} से ज़्यादा है`); c.paid += payment; c.history.push({ amount: payment, date: new Date().toLocaleString("hi-IN"), note: "Payment" }); saveData(); closePaymentModal(); displayCustomers(); if (c.paid >= c.total) { toast("🎉 खाता क्लियर हो गया!"); } else { toast(`✅ ${fmt(payment)} जमा हो गया`); } } function clearAccount(id) { const c = customers.find(c => c.id === id); if (!c) return; const remaining = c.total - c.paid; if (remaining <= 0) return toast("✅ पहले से क्लियर है"); if (!confirm(`${c.name} का ${fmt(remaining)} बाकी — क्लियर करें?`)) return; c.paid = c.total; c.history.push({ amount: remaining, date: new Date().toLocaleString("hi-IN"), note: "✅ खाता क्लियर" }); saveData(); displayCustomers(); toast("✅ खाता क्लियर!"); } function openEdit(id) { const c = customers.find(c => c.id === id); if (!c) return; document.getElementById("editId").value = c.id; document.getElementById("editName").value = c.name; document.getElementById("editPhone").value = c.phone; document.getElementById("editTotal").value = c.total; document.getElementById("editModal").classList.add("active"); } function closeModal() { document.getElementById("editModal").classList.remove("active"); } function saveEdit() { const id = Number(document.getElementById("editId").value); const name = document.getElementById("editName").value.trim(); const phone = document.getElementById("editPhone").value.trim(); const total = Number(document.getElementById("editTotal").value); if (!name) return toast("⚠️ नाम खाली नहीं हो सकता"); if (!total || total <= 0) return toast("⚠️ रकम सही डालें"); if (!isValidPhone(phone)) return toast("⚠️ मोबाइल नंबर जांचें"); const c = customers.find(c => c.id === id); if (!c) return; c.name = name; c.phone = phone; c.total = total; if (c.paid > c.total) c.paid = c.total; saveData(); closeModal(); displayCustomers(); toast("✏️ अपडेट हो गया!"); } function deleteCustomer(id) { const c = customers.find(c => c.id === id); if (!c) return; if (!confirm(`"${c.name}" का पूरा रिकॉर्ड हटाएं?`)) return; customers = customers.filter(c => c.id !== id); saveData(); displayCustomers(); toast("🗑️ ग्राहक हटा दिया गया"); } function sendWhatsApp(id) { const c = customers.find(c => c.id === id); if (!c || !c.phone) return toast("⚠️ मोबाइल नंबर नहीं है"); const remaining = c.total - c.paid; const msg = encodeURIComponent( `नमस्ते ${c.name} जी 🙏\n\n` + `आपका बकाया विवरण:\n` + `कुल रकम: ${fmt(c.total)}\n` + `जमा: ${fmt(c.paid)}\n` + `बाकी: ${fmt(remaining)}\n\n` + `कृपया जल्द भुगतान करें। धन्यवाद! 🙏` ); const phoneClean = c.phone.replace(/\D/g, ""); const fullPhone = phoneClean.length === 10 ? "91" + phoneClean : phoneClean; window.open(`https://wa.me/${fullPhone}?text=${msg}`, "_blank"); } /* ── Export / Import ── */ function exportData() { if (!customers.length) return toast("⚠️ कोई डेटा नहीं है"); const blob = new Blob( [JSON.stringify(customers, null, 2)], { type: "application/json" } ); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `digital-khata-backup-${new Date().toISOString().slice(0,10)}.json`; a.click(); URL.revokeObjectURL(url); toast("📤 बैकअप डाउनलोड हो गया!"); } function importData(event) { const file = event.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = function(e) { try { const data = JSON.parse(e.target.result); if (!Array.isArray(data)) throw new Error(); const count = data.length; if (!confirm(`${count} ग्राहक मिले। मौजूदा डेटा में जोड़ें?\n\nOK = जोड़ें\nCancel = बदलें`)) { customers = data; } else { customers = [...customers, ...data]; } saveData(); displayCustomers(); toast(`📥 ${count} ग्राहक रिस्टोर हुए!`); } catch { toast("❌ फाइल सही नहीं है"); } }; reader.readAsText(file); event.target.value = ""; } /* ── Display ── */ function displayCustomers() { const list = document.getElementById("customerList"); const search = document.getElementById("search").value.toLowerCase(); const sort = document.getElementById("sortSelect").value; const filter = document.getElementById("filterSelect").value; let filtered = customers.filter(c => c.name.toLowerCase().includes(search) || c.phone.toLowerCase().includes(search) ); if (filter === "pending") filtered = filtered.filter(c => c.paid < c.total); if (filter === "cleared") filtered = filtered.filter(c => c.paid >= c.total); filtered.sort((a, b) => { switch (sort) { case "newest": return b.id - a.id; case "oldest": return a.id - b.id; case "highest": return (b.total - b.paid) - (a.total - a.paid); case "lowest": return (a.total - a.paid) - (b.total - b.paid); case "name": return a.name.localeCompare(b.name, "hi"); default: return 0; } }); updateDashboard(); if (!filtered.length) { list.innerHTML = `<div class="empty">📭 कोई ग्राहक नहीं मिला</div>`; return; } list.innerHTML = filtered.map(c => { const remaining = c.total - c.paid; const isClear = remaining <= 0; const historyHTML = c.history.length ? c.history.map(h => ` <div> <b>${fmt(h.amount)}</b> — ${h.date} ${h.note ? `<small>(${escapeHTML(h.note)})</small>` : ""} </div>`).join("") : "कोई history नहीं"; return ` <div class="customer ${isClear ? "cleared" : ""}"> <div class="customer-header"> <div> <h3>👤 ${escapeHTML(c.name)}</h3> <small>📱 ${escapeHTML(c.phone || "नंबर नहीं")}</small> </div> <span class="status ${isClear ? "clear" : "pending"}"> ${isClear ? "✅ क्लियर" : "🔴 बकाया"} </span> </div> <div class="amounts"> <div class="amount-box"> <span class="val">${fmt(c.total)}</span> <span class="lbl">कुल रकम</span> </div> <div class="amount-box"> <span class="val" style="color:#16a34a">${fmt(c.paid)}</span> <span class="lbl">जमा</span> </div> <div class="amount-box"> <span class="val" style="color:${isClear ? "#16a34a" : "#dc2626"}"> ${fmt(remaining)} </span> <span class="lbl">बाकी</span> </div> </div> <div class="history"> <b>📜 Payment History</b> ${historyHTML} </div> <div class="actions"> ${!isClear ? ` <button class="payment-btn" onclick="openPaymentModal(${c.id})">💵 जमा</button> <button class="clear-btn" onclick="clearAccount(${c.id})">✅ क्लियर</button> ` : ""} <button class="edit-btn" onclick="openEdit(${c.id})">✏️</button> <button class="wa-btn" onclick="sendWhatsApp(${c.id})">📲 WhatsApp</button> <button class="delete-btn" onclick="deleteCustomer(${c.id})">🗑️</button> </div> </div>`; }).join(""); } /* ── Keyboard shortcuts ── */ document.addEventListener("keydown", e => { if (e.key === "Escape") { closeModal(); closePaymentModal(); } }); /* ── Init ── */ displayCustomers(); </script> </body> </html> Assistant
- User
Pakistan me lia
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.