Smart CSC Tools

CSC Management Tools

Complete Financial Management for CSC VLE

Customers

0

Today

Services

0

Today

Pending

0

Completed

0

Today

₹0

Monthly

₹0

Pending Amt

₹0

Profit

₹0

Financial Overview (This Year)

Service Distribution

Recent Customers

View All
Name Services Status Date Amount Action
No customers yet
`); printWindow.document.close(); } // Share Slip via WhatsApp (Fixed) function shareSlip() { if (!currentSlipCustomerId) { showToast('No slip selected', 'error'); return; } const customer = customers.find(c => c.id === currentSlipCustomerId); if (!customer) return; // Create service list let serviceList = ''; customer.services.forEach((s, i) => { serviceList += `• ${s.type}: ₹${s.amount}%0a`; }); // Create message const message = `📄 *${centerInfo.name}*%0a📞 ${centerInfo.mobile}%0a%0a👤 *Customer:* ${customer.name}%0a📱 Mobile: ${customer.mobile}%0a%0a🛠️ *Services:*%0a${serviceList}%0a💰 *Total: ₹${customer.totalAmount}*%0a💵 Paid: ₹${customer.paidAmount}%0a⚡ Due: ₹${customer.remainingAmount}%0a%0a📅 Work Date: ${formatDate(customer.workDate)}%0a📦 Expected: ${formatDate(customer.expectedDelivery)}%0a%0a✅ Thank you for choosing ${centerInfo.name}!`; const url = `https://wa.me/91${customer.mobile}?text=${message}`; window.open(url, '_blank'); showToast('WhatsApp opened!', 'success'); } // Close Edit Modal function closeEditModal() { document.getElementById('editModal').style.display = 'none'; } // Send WhatsApp function sendWhatsApp(mobile, name) { if (!mobile) { showToast('Mobile number not available', 'error'); return; } const message = `Hello ${name}, your work is in process at ${centerInfo.name}. For any queries, contact ${centerInfo.mobile}. Thank you!`; const url = `https://wa.me/91${mobile}?text=${encodeURIComponent(message)}`; window.open(url, '_blank'); } // Render Pending Work function renderPendingWork() { const pending = customers.filter(c => c.status !== 'Completed'); const tbody = document.getElementById('pendingWorkTableBody'); if (!tbody) return; if (pending.length === 0) { tbody.innerHTML = 'No pending work'; document.getElementById('totalPendingCount').textContent = '0'; document.getElementById('overdueCount').textContent = '0'; document.getElementById('urgentCount').textContent = '0'; document.getElementById('pendingAmountTotal').textContent = '₹0'; return; } let html = ''; let overdue = 0; let urgent = 0; let totalPendingAmount = 0; pending.forEach(customer => { const today = new Date(); const deliveryDate = new Date(customer.expectedDelivery); const daysPending = Math.ceil((today - deliveryDate) / (1000 * 60 * 60 * 24)); if (daysPending > 0) { if (daysPending > 15) urgent++; else if (daysPending > 7) overdue++; } totalPendingAmount += customer.remainingAmount || 0; const statusClass = daysPending > 15 ? 'bg-red-100 text-red-800' : daysPending > 7 ? 'bg-orange-100 text-orange-800' : 'bg-yellow-100 text-yellow-800'; // Get service names const serviceNames = customer.services ? customer.services.map(s => s.type).join(', ') : '-'; html += ` ${customer.name || '-'} ${serviceNames} ${formatDate(customer.workDate)} ${formatDate(customer.expectedDelivery)} ${daysPending > 0 ? daysPending + ' days' : 'On Time'} ₹${customer.remainingAmount || 0} ${customer.status || 'Pending'} `; }); tbody.innerHTML = html; document.getElementById('totalPendingCount').textContent = pending.length; document.getElementById('overdueCount').textContent = overdue; document.getElementById('urgentCount').textContent = urgent; document.getElementById('pendingAmountTotal').textContent = `₹${totalPendingAmount}`; } // Render Categories function renderCategories() { const container = document.getElementById('categoriesContainer'); if (!container) return; let html = ''; serviceCategories.forEach(category => { let servicesHtml = ''; category.services.forEach(service => { servicesHtml += `
${service.name}

${service.desc || ''} | ₹${service.price || 0}

`; }); html += `

${category.name}

${servicesHtml}
`; }); // Add button for new category at the bottom html += ` `; container.innerHTML = html; } // Add Category function addCategory() { const name = document.getElementById('newCategoryName')?.value; if (!name) { showToast('Please enter category name', 'error'); return; } const newCategory = { id: Date.now(), name: name, services: [] }; serviceCategories.push(newCategory); saveToLocalStorage(); renderCategories(); initializeServiceDropdowns(); document.getElementById('newCategoryName').value = ''; showToast('Category added successfully!', 'success'); } // Delete Category function deleteCategory(categoryId) { if (confirm('Are you sure? All services in this category will also be deleted.')) { serviceCategories = serviceCategories.filter(c => c.id !== categoryId); saveToLocalStorage(); renderCategories(); initializeServiceDropdowns(); showToast('Category deleted', 'success'); } } // Open Add Service Modal function openAddServiceModal(categoryId) { document.getElementById('serviceCategoryId').value = categoryId; document.getElementById('addServiceForm').reset(); document.getElementById('addServiceModal').style.display = 'block'; } // Close Add Service Modal function closeAddServiceModal() { document.getElementById('addServiceModal').style.display = 'none'; } // Add Service to Category function addServiceToCategory() { const categoryId = parseInt(document.getElementById('serviceCategoryId').value); const name = document.getElementById('serviceName').value; const desc = document.getElementById('serviceDesc').value; const price = parseFloat(document.getElementById('servicePrice').value) || 0; if (!name) { showToast('Please enter service name', 'error'); return; } const category = serviceCategories.find(c => c.id === categoryId); if (category) { const newService = { id: Date.now(), name: name, desc: desc, price: price }; category.services.push(newService); saveToLocalStorage(); renderCategories(); initializeServiceDropdowns(); closeAddServiceModal(); showToast('Service added successfully!', 'success'); } } // Edit Service function editService(categoryId, serviceId) { const category = serviceCategories.find(c => c.id === categoryId); if (!category) return; const service = category.services.find(s => s.id === serviceId); if (!service) return; const newName = prompt('Edit service name:', service.name); if (newName) { service.name = newName; const newDesc = prompt('Edit description:', service.desc || ''); if (newDesc !== null) service.desc = newDesc; const newPrice = prompt('Edit price (₹):', service.price); if (newPrice !== null) service.price = parseFloat(newPrice) || 0; saveToLocalStorage(); renderCategories(); initializeServiceDropdowns(); showToast('Service updated', 'success'); } } // Delete Service function deleteService(categoryId, serviceId) { if (confirm('Delete this service?')) { const category = serviceCategories.find(c => c.id === categoryId); if (category) { category.services = category.services.filter(s => s.id !== serviceId); saveToLocalStorage(); renderCategories(); initializeServiceDropdowns(); showToast('Service deleted', 'success'); } } } // Update Customer Select for History function updateCustomerSelect() { const select = document.getElementById('historyCustomerSelect'); if (!select) return; const uniqueCustomers = [...new Map(customers.map(c => [c.mobile, c])).values()]; let options = ''; uniqueCustomers.forEach(customer => { options += ``; }); select.innerHTML = options; } // Show Customer History function showCustomerHistory() { const mobile = document.getElementById('historyCustomerSelect').value; if (!mobile) { document.getElementById('customerHistoryDisplay').classList.add('hidden'); return; } const customerRecords = customers.filter(c => c.mobile === mobile); const customer = customerRecords[0]; if (!customer) return; document.getElementById('historyCustomerName').textContent = customer.name || 'Unknown'; document.getElementById('historyMobile').textContent = customer.mobile; document.getElementById('historyAddress').textContent = customer.address || 'N/A'; document.getElementById('historyTotalServices').textContent = customerRecords.length; const totalAmount = customerRecords.reduce((sum, c) => sum + (c.totalAmount || 0), 0); const paidAmount = customerRecords.reduce((sum, c) => sum + (c.paidAmount || 0), 0); const dueAmount = totalAmount - paidAmount; document.getElementById('historyTotalAmount').textContent = `₹${totalAmount}`; document.getElementById('historyPaidAmount').textContent = `₹${paidAmount}`; document.getElementById('historyDueAmount').textContent = `₹${dueAmount}`; let html = ''; customerRecords.sort((a, b) => new Date(b.workDate) - new Date(a.workDate)).forEach(record => { // Get service names const serviceNames = record.services ? record.services.map(s => s.type).join(', ') : '-'; html += ` ${formatDate(record.workDate)} ${serviceNames} ${record.services ? record.services[0].description : '-'} ${record.status || 'Pending'} ₹${record.totalAmount || 0} `; }); document.getElementById('customerHistoryTable').innerHTML = html; document.getElementById('customerHistoryDisplay').classList.remove('hidden'); } // Print Customer Slip (from history) function printCustomerSlip() { const mobile = document.getElementById('historyCustomerSelect').value; if (!mobile) return; const customerRecords = customers.filter(c => c.mobile === mobile); if (customerRecords.length === 0) return; // Show slip for latest record showCustomerSlip(customerRecords[0].id); } // Load Center Info function loadCenterInfo() { document.getElementById('centerName').value = centerInfo.name || ''; document.getElementById('ownerName').value = centerInfo.owner || ''; document.getElementById('centerMobile').value = centerInfo.mobile || ''; document.getElementById('centerEmail').value = centerInfo.email || ''; document.getElementById('centerAddress').value = centerInfo.address || ''; document.getElementById('centerGST').value = centerInfo.gst || ''; document.getElementById('workingHours').value = centerInfo.hours || ''; document.getElementById('welcomeMessage').value = centerInfo.welcomeMsg || ''; updateCenterPreview(); } // Save Center Info function saveCenterInfo() { centerInfo = { name: document.getElementById('centerName').value, owner: document.getElementById('ownerName').value, mobile: document.getElementById('centerMobile').value, email: document.getElementById('centerEmail').value, address: document.getElementById('centerAddress').value, gst: document.getElementById('centerGST').value, hours: document.getElementById('workingHours').value, welcomeMsg: document.getElementById('welcomeMessage').value }; saveToLocalStorage(); updateCenterPreview(); showToast('Center information saved successfully!', 'success'); } // Update Center Preview function updateCenterPreview() { document.getElementById('previewCenterName').textContent = centerInfo.name || 'Smart CSC Center'; document.getElementById('previewOwner').textContent = `VLE: ${centerInfo.owner || 'Your Name'}`; document.getElementById('previewAddress').textContent = centerInfo.address || 'Address will appear here'; document.getElementById('previewContact').textContent = `Mobile: ${centerInfo.mobile || '-'} | Email: ${centerInfo.email || '-'}`; } // Update Dashboard function updateDashboard() { const today = new Date().toISOString().split('T')[0]; const todayCustomers = customers.filter(c => c.workDate === today).length; const todayServices = customers.reduce((total, c) => { if (c.workDate === today) { return total + (c.services ? c.services.length : 1); } return total; }, 0); const pendingWork = customers.filter(c => c.status !== 'Completed').length; const completedWork = customers.filter(c => c.status === 'Completed').length; const todayIncome = customers .filter(c => c.workDate === today) .reduce((sum, c) => sum + (c.paidAmount || 0), 0); const currentMonth = new Date().getMonth(); const currentYear = new Date().getFullYear(); const monthlyIncome = customers .filter(c => { if (!c.workDate) return false; const date = new Date(c.workDate); return date.getMonth() === currentMonth && date.getFullYear() === currentYear; }) .reduce((sum, c) => sum + (c.paidAmount || 0), 0); const totalPendingAmount = customers.reduce((sum, c) => sum + (c.remainingAmount || 0), 0); // Calculate monthly profit const monthlyExpense = expenses .filter(e => e.month === currentMonth && e.year === currentYear) .reduce((sum, e) => sum + (e.amount || 0), 0); const monthlyProfit = monthlyIncome - monthlyExpense; document.getElementById('totalCustomersToday').textContent = todayCustomers; document.getElementById('totalServicesToday').textContent = todayServices; document.getElementById('pendingWork').textContent = pendingWork; document.getElementById('completedWork').textContent = completedWork; document.getElementById('todayIncome').textContent = `₹${todayIncome}`; document.getElementById('monthlyIncome').textContent = `₹${monthlyIncome}`; document.getElementById('totalPendingAmount').textContent = `₹${totalPendingAmount}`; document.getElementById('monthlyProfit').textContent = `₹${monthlyProfit}`; // Update recent customers table updateRecentCustomers(); } // Update Recent Customers function updateRecentCustomers() { const recent = customers.slice(-5).reverse(); const tbody = document.getElementById('recentCustomersTable'); if (!tbody) return; if (recent.length === 0) { tbody.innerHTML = 'No customers yet'; return; } let html = ''; recent.forEach(customer => { const statusClass = customer.status === 'Completed' ? 'status-completed' : customer.status === 'In Process' ? 'status-inprocess' : 'status-pending'; // Get service names const serviceNames = customer.services ? customer.services.map(s => s.type).join(', ') : '-'; html += ` ${customer.name || '-'} ${serviceNames} ${customer.status || 'Pending'} ${formatDate(customer.workDate)} ₹${customer.totalAmount || 0} `; }); tbody.innerHTML = html; } // Generate Report function generateReport() { const type = document.getElementById('reportType').value; const date = document.getElementById('reportDate').value; const month = document.getElementById('reportMonth').value; const year = document.getElementById('reportYear').value || new Date().getFullYear(); let filtered = []; if (type === 'daily' && date) { filtered = customers.filter(c => c.workDate === date); } else if (type === 'monthly' && month) { filtered = customers.filter(c => { if (!c.workDate) return false; const cDate = new Date(c.workDate); return cDate.getMonth() + 1 === parseInt(month) && cDate.getFullYear() === parseInt(year); }); } else { showToast('Please select date/month', 'warning'); return; } // Update report stats document.getElementById('reportTotalCustomers').textContent = filtered.length; const totalServices = filtered.reduce((total, c) => { return total + (c.services ? c.services.length : 1); }, 0); document.getElementById('reportTotalServices').textContent = totalServices; const totalIncome = filtered.reduce((sum, c) => sum + (c.paidAmount || 0), 0); const pendingAmount = filtered.reduce((sum, c) => sum + (c.remainingAmount || 0), 0); document.getElementById('reportTotalIncome').textContent = `₹${totalIncome}`; document.getElementById('reportPendingAmount').textContent = `₹${pendingAmount}`; // Render report table let html = ''; if (filtered.length === 0) { html = 'No data found'; } else { filtered.sort((a, b) => new Date(b.workDate) - new Date(a.workDate)).forEach(c => { // Get service names const serviceNames = c.services ? c.services.map(s => s.type).join(', ') : '-'; html += ` ${formatDate(c.workDate)} ${c.name || '-'} ${serviceNames} ${c.status || 'Pending'} ₹${c.totalAmount || 0} ₹${c.paidAmount || 0} ₹${c.remainingAmount || 0} `; }); } document.getElementById('reportTableBody').innerHTML = html; document.getElementById('reportResults').classList.remove('hidden'); } // Export Financial Report to PDF function exportFinancialToPDF() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Add title doc.setFontSize(20); doc.setTextColor(102, 126, 234); doc.text('Financial Report - Smart CSC Tools', 20, 20); // Add center info doc.setFontSize(12); doc.setTextColor(0, 0, 0); doc.text(centerInfo.name, 20, 30); doc.text(centerInfo.address, 20, 35); doc.text(`VLE: ${centerInfo.owner} | ${centerInfo.mobile}`, 20, 40); // Add date const today = new Date().toLocaleDateString(); doc.text(`Generated on: ${today}`, 20, 50); // Add summary doc.setFontSize(14); doc.setTextColor(102, 126, 234); doc.text('Monthly Summary', 20, 65); doc.setFontSize(12); doc.setTextColor(0, 0, 0); const monthlyIncome = document.getElementById('financialMonthlyIncome').textContent; const monthlyExpense = document.getElementById('financialMonthlyExpense').textContent; const monthlyProfit = document.getElementById('financialMonthlyProfit').textContent; const profitMargin = document.getElementById('financialProfitMargin').textContent; doc.text(`Monthly Income: ${monthlyIncome}`, 20, 75); doc.text(`Monthly Expense: ${monthlyExpense}`, 20, 82); doc.text(`Monthly Profit: ${monthlyProfit}`, 20, 89); doc.text(`Profit Margin: ${profitMargin}`, 20, 96); // Add expense table doc.setFontSize(14); doc.setTextColor(102, 126, 234); doc.text('Expense History', 20, 111); // Prepare table data const tableColumn = ["Date", "Category", "Description", "Amount"]; const tableRows = []; expenses.slice(0, 10).forEach(exp => { const expData = [ exp.dateStr || formatDate(exp.date), exp.category || 'Other', exp.description || '-', `₹${exp.amount}` ]; tableRows.push(expData); }); // Add table doc.autoTable({ startY: 115, head: [tableColumn], body: tableRows, theme: 'striped', headStyles: { fillColor: [102, 126, 234] } }); // Save PDF doc.save(`financial_report_${today.replace(/\//g, '-')}.pdf`); showToast('Financial report downloaded!', 'success'); } // Export Report to PDF function exportReportToPDF() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Add title doc.setFontSize(20); doc.setTextColor(102, 126, 234); doc.text('Customer Report - Smart CSC Tools', 20, 20); // Add center info doc.setFontSize(12); doc.setTextColor(0, 0, 0); doc.text(centerInfo.name, 20, 30); doc.text(centerInfo.address, 20, 35); doc.text(`VLE: ${centerInfo.owner} | ${centerInfo.mobile}`, 20, 40); // Add date const today = new Date().toLocaleDateString(); doc.text(`Generated on: ${today}`, 20, 50); // Add summary stats doc.setFontSize(14); doc.setTextColor(102, 126, 234); doc.text('Summary', 20, 65); doc.setFontSize(12); doc.setTextColor(0, 0, 0); const totalCustomers = document.getElementById('reportTotalCustomers').textContent; const totalServices = document.getElementById('reportTotalServices').textContent; const totalIncome = document.getElementById('reportTotalIncome').textContent; const pendingAmount = document.getElementById('reportPendingAmount').textContent; doc.text(`Total Customers: ${totalCustomers}`, 20, 75); doc.text(`Total Services: ${totalServices}`, 20, 82); doc.text(`Total Income: ${totalIncome}`, 20, 89); doc.text(`Pending Amount: ${pendingAmount}`, 20, 96); // Add report table doc.setFontSize(14); doc.setTextColor(102, 126, 234); doc.text('Customer Details', 20, 111); // Prepare table data const tableColumn = ["Date", "Customer", "Services", "Status", "Total"]; const tableRows = []; customers.slice(0, 15).forEach(c => { const serviceNames = c.services ? c.services.map(s => s.type).join(', ') : '-'; const cData = [ formatDate(c.workDate), c.name || '-', serviceNames, c.status || 'Pending', `₹${c.totalAmount || 0}` ]; tableRows.push(cData); }); // Add table doc.autoTable({ startY: 115, head: [tableColumn], body: tableRows, theme: 'striped', headStyles: { fillColor: [102, 126, 234] } }); // Save PDF doc.save(`customer_report_${today.replace(/\//g, '-')}.pdf`); showToast('Report downloaded!', 'success'); } // Export to Excel function exportToExcel() { if (customers.length === 0) { showToast('No data to export', 'warning'); return; } const exportData = customers.flatMap(c => { if (c.services && c.services.length > 0) { return c.services.map(s => ({ 'Customer Name': c.name || '', 'Mobile': c.mobile || '', 'Address': c.address || '', 'Service': s.type || '', 'Description': s.description || '', 'Work Date': c.workDate || '', 'Expected Delivery': c.expectedDelivery || '', 'Status': c.status || '', 'Service Amount': s.amount || 0, 'Total Bill': c.totalAmount || 0, 'Paid Amount': c.paidAmount || 0, 'Due Amount': c.remainingAmount || 0, 'Payment Status': c.paymentStatus || '' })); } else { return [{ 'Customer Name': c.name || '', 'Mobile': c.mobile || '', 'Address': c.address || '', 'Service': '-', 'Description': '-', 'Work Date': c.workDate || '', 'Expected Delivery': c.expectedDelivery || '', 'Status': c.status || '', 'Service Amount': 0, 'Total Bill': c.totalAmount || 0, 'Paid Amount': c.paidAmount || 0, 'Due Amount': c.remainingAmount || 0, 'Payment Status': c.paymentStatus || '' }]; } }); const ws = XLSX.utils.json_to_sheet(exportData); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, 'Customers'); XLSX.writeFile(wb, `smart_csc_customers_${new Date().toISOString().split('T')[0]}.xlsx`); showToast('Excel file downloaded!', 'success'); } // Print Invoice function printInvoice() { if (customers.length === 0) { showToast('No data to print', 'warning'); return; } const printWindow = window.open('', '_blank'); if (!printWindow) { showToast('Please allow popups', 'error'); return; } let html = ` ${centerInfo.name} - Customer Report

${centerInfo.name}

${centerInfo.address}

VLE: ${centerInfo.owner} | ${centerInfo.mobile}

${centerInfo.email}


CSC Customer Report

Date: ${new Date().toLocaleDateString()}

Total Customers

${customers.length}

Total Revenue

₹${customers.reduce((sum, c) => sum + (c.paidAmount || 0), 0)}

Pending Amount

₹${customers.reduce((sum, c) => sum + (c.remainingAmount || 0), 0)}

`; customers.slice(0, 50).forEach(c => { const serviceNames = c.services ? c.services.map(s => s.type).join(', ') : '-'; html += ` `; }); html += `
Name Mobile Services Status Total Paid Due
${c.name || ''} ${c.mobile || ''} ${serviceNames} ${c.status || ''} ₹${c.totalAmount || 0} ₹${c.paidAmount || 0} ₹${c.remainingAmount || 0}

Generated by Smart CSC Tools - www.smart-csc-tools-sovitx.vercel.apl

`; printWindow.document.write(html); printWindow.document.close(); printWindow.print(); } // Clear Database function clearDatabase() { if (confirm('⚠️ Are you sure? This will delete ALL customer data permanently!')) { customers = []; localStorage.removeItem('smartCscCustomers'); saveToLocalStorage(); showToast('Database cleared!', 'warning'); } } // Clear Form function clearForm() { if (confirm('Clear all form fields?')) { document.getElementById('customerForm').reset(); setDefaultDates(); // Reset services to just one const container = document.getElementById('servicesContainer'); if (container) { container.innerHTML = ''; addServiceRow(); } document.getElementById('totalAmount').value = '0'; document.getElementById('paidAmount').value = '0'; document.getElementById('remainingAmount').value = '0'; } } // Format Date function formatDate(dateString) { if (!dateString) return '-'; try { const date = new Date(dateString); if (isNaN(date.getTime())) return '-'; return date.toLocaleDateString('en-IN', { day: '2-digit', month: '2-digit', year: 'numeric' }); } catch (e) { return '-'; } } // Show Toast Notification function showToast(message, type = 'info') { const container = document.getElementById('toastContainer'); if (!container) return; const toast = document.createElement('div'); const colors = { success: 'bg-green-500', error: 'bg-red-500', warning: 'bg-yellow-500', info: 'bg-blue-500' }; const icons = { success: 'fa-check-circle', error: 'fa-exclamation-circle', warning: 'fa-exclamation-triangle', info: 'fa-info-circle' }; toast.className = `toast ${colors[type]} text-white px-6 py-3 rounded-lg shadow-lg flex items-center animate-slideIn`; toast.innerHTML = ` ${message} `; container.appendChild(toast); setTimeout(() => { if (toast.parentNode) { toast.remove(); } }, 3000); } // Check for Notifications function checkForNotifications() { const pending = customers.filter(c => c.status !== 'Completed').length; const badge = document.getElementById('notificationBadge'); if (badge) { badge.textContent = pending; if (pending > 0) { badge.style.display = 'flex'; } else { badge.style.display = 'none'; } } } // Show Notifications function showNotifications() { const pending = customers.filter(c => c.status !== 'Completed'); if (pending.length === 0) { showToast('No pending notifications', 'info'); return; } let message = `${pending.length} pending works:\n`; pending.slice(0, 3).forEach(c => { message += `\n• ${c.name || 'Unknown'} - ₹${c.remainingAmount || 0} due`; }); if (pending.length > 3) { message += `\n\n...and ${pending.length - 3} more`; } alert(message); } // Toggle Dark Mode - Fixed function toggleDarkMode() { isDarkMode = !isDarkMode; const body = document.body; const icon = document.getElementById('darkModeIcon'); const text = document.getElementById('darkModeText'); if (isDarkMode) { body.classList.add('dark-mode'); icon.classList.remove('fa-moon'); icon.classList.add('fa-sun'); if (text) text.textContent = 'Light Mode'; localStorage.setItem('smartCscDarkMode', 'true'); } else { body.classList.remove('dark-mode'); icon.classList.remove('fa-sun'); icon.classList.add('fa-moon'); if (text) text.textContent = 'Dark Mode'; localStorage.setItem('smartCscDarkMode', 'false'); } } // Toggle Mobile Search function toggleMobileSearch() { const mobileSearch = document.getElementById('mobileSearch'); if (mobileSearch) { mobileSearch.classList.toggle('hidden'); } } // Show Section function showSection(section) { // Hide all sections document.querySelectorAll('.section').forEach(s => s.classList.add('hidden')); // Show selected section const selectedSection = document.getElementById(section + 'Section'); if (selectedSection) { selectedSection.classList.remove('hidden'); } // Update page title const titles = { dashboard: 'Dashboard', financial: 'Financial Management', customers: 'Add Customer', workmanager: 'Work Manager', pending: 'Pending Work', services: 'Services', center: 'Center Info', reports: 'Reports', history: 'Customer History' }; const pageTitle = document.getElementById('pageTitle'); if (pageTitle) { pageTitle.textContent = titles[section] || 'Dashboard'; } // Update active nav item document.querySelectorAll('.nav-item').forEach(item => { item.classList.remove('bg-purple-700'); if (item.dataset && item.dataset.section === section) { item.classList.add('bg-purple-700'); } }); // Refresh data if needed if (section === 'dashboard') { updateDashboard(); setTimeout(() => initializeAllCharts(), 100); } else if (section === 'financial') { updateFinancialSummary(); renderExpenseHistory(); setTimeout(() => { initializeMonthlyComparisonChart(); initializeProfitDistributionChart(); }, 100); } else if (section === 'workmanager') { renderWorkManager(); initializeServiceDropdowns(); } else if (section === 'pending') { renderPendingWork(); } else if (section === 'history') { updateCustomerSelect(); } else if (section === 'services') { renderCategories(); } else if (section === 'center') { loadCenterInfo(); } } // Click outside modal to close window.onclick = function(event) { const editModal = document.getElementById('editModal'); const slipModal = document.getElementById('slipModal'); const addServiceModal = document.getElementById('addServiceModal'); if (event.target === editModal) { closeEditModal(); } if (event.target === slipModal) { closeSlipModal(); } if (event.target === addServiceModal) { closeAddServiceModal(); } };