Spaces:
Running
Running
Download index.html from lmaeshff/ranasweets: direct link, hf CLI and curl.
- Browser
- Download file 41 kB
-
https://huggingface.co/spaces/lmaeshff/ranasweets/resolve/main/index.html
- Command line
-
hf download hf://spaces/lmaeshff/ranasweets/index.html
-
curl -L -o index.html https://huggingface.co/spaces/lmaeshff/ranasweets/resolve/main/index.html
41 kB
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <!-- Previous head content remains the same --> | |
| </head> | |
| <body class="bg-gray-100"> | |
| <!-- All previous HTML content remains the same until the script section --> | |
| <script> | |
| // Database simulation (same as before) | |
| let ordersDB = JSON.parse(localStorage.getItem('ranaSweetOrders')) || []; | |
| let suppliersDB = JSON.parse(localStorage.getItem('ranaSweetSuppliers')) || []; | |
| let inventoryDB = JSON.parse(localStorage.getItem('ranaSweetInventory')) || { | |
| chhena: 0, | |
| sugar: 0, | |
| containers: 10 | |
| }; | |
| let paymentHistoryDB = JSON.parse(localStorage.getItem('ranaSweetPaymentHistory')) || []; | |
| let supplierCallHistoryDB = JSON.parse(localStorage.getItem('ranaSweetSupplierCallHistory')) || []; | |
| let inventoryHistoryDB = JSON.parse(localStorage.getItem('ranaSweetInventoryHistory')) || []; | |
| // Sweet types and their chhena requirements (same as before) | |
| const sweetTypes = { | |
| rasgulla: { | |
| '5': { chhena: 11, containerCapacity: 333 }, | |
| '6': { chhena: 12, containerCapacity: 300 }, | |
| '7': { chhena: 13, containerCapacity: 250 }, | |
| '8': { chhena: 16, containerCapacity: 200 } | |
| }, | |
| kalakand: { | |
| '10': { chhena: 20, containerCapacity: 150 }, | |
| '12': { chhena: 25, containerCapacity: 120 } | |
| }, | |
| sondesh: { | |
| '10': { chhena: 18, containerCapacity: 180 }, | |
| '12': { chhena: 22, containerCapacity: 150 } | |
| } | |
| }; | |
| // Sugar requirement ratio (same as before) | |
| const sugarRatio = 0.1; | |
| // Current user (same as before) | |
| const currentUser = "Admin"; | |
| // Initialize the app (same as before) | |
| document.addEventListener('DOMContentLoaded', function() { | |
| initMenu(); | |
| initSweetSelection(); | |
| initOrderForm(); | |
| initModals(); | |
| initCalendar(); | |
| initInventoryControls(); | |
| updateDashboard(); | |
| renderAllOrders(); | |
| renderSuppliers(); | |
| renderPaymentDue(); | |
| renderPaymentHistory(); | |
| renderSupplierCallHistory(); | |
| updateInventoryDisplay(); | |
| renderInventoryHistory(); | |
| const today = new Date(); | |
| const tomorrow = new Date(today); | |
| tomorrow.setDate(tomorrow.getDate() + 1); | |
| document.getElementById('deliveryDate').valueAsDate = tomorrow; | |
| }); | |
| // Initialize inventory controls | |
| function initInventoryControls() { | |
| // Chhena update | |
| document.getElementById('updateChhena').addEventListener('click', function() { | |
| const amount = parseFloat(document.getElementById('addChhena').value); | |
| if (isNaN(amount) || amount <= 0) { | |
| alert('Please enter a valid amount'); | |
| return; | |
| } | |
| inventoryDB.chhena += amount; | |
| localStorage.setItem('ranaSweetInventory', JSON.stringify(inventoryDB)); | |
| // Add to history | |
| inventoryHistoryDB.push({ | |
| date: new Date().toISOString().split('T')[0], | |
| type: 'chhena', | |
| quantity: amount, | |
| action: 'added', | |
| updatedBy: currentUser | |
| }); | |
| localStorage.setItem('ranaSweetInventoryHistory', JSON.stringify(inventoryHistoryDB)); | |
| updateInventoryDisplay(); | |
| renderInventoryHistory(); | |
| document.getElementById('addChhena').value = '0'; | |
| }); | |
| // Sugar update | |
| document.getElementById('updateSugar').addEventListener('click', function() { | |
| const amount = parseFloat(document.getElementById('addSugar').value); | |
| if (isNaN(amount) || amount <= 0) { | |
| alert('Please enter a valid amount'); | |
| return; | |
| } | |
| inventoryDB.sugar += amount; | |
| localStorage.setItem('ranaSweetInventory', JSON.stringify(inventoryDB)); | |
| // Add to history | |
| inventoryHistoryDB.push({ | |
| date: new Date().toISOString().split('T')[0], | |
| type: 'sugar', | |
| quantity: amount, | |
| action: 'added', | |
| updatedBy: currentUser | |
| }); | |
| localStorage.setItem('ranaSweetInventoryHistory', JSON.stringify(inventoryHistoryDB)); | |
| updateInventoryDisplay(); | |
| renderInventoryHistory(); | |
| document.getElementById('addSugar').value = '0'; | |
| }); | |
| // Containers update | |
| document.getElementById('updateContainers').addEventListener('click', function() { | |
| const amount = parseInt(document.getElementById('addContainers').value); | |
| if (isNaN(amount) || amount <= 0) { | |
| alert('Please enter a valid amount'); | |
| return; | |
| } | |
| inventoryDB.containers += amount; | |
| localStorage.setItem('ranaSweetInventory', JSON.stringify(inventoryDB)); | |
| // Add to history | |
| inventoryHistoryDB.push({ | |
| date: new Date().toISOString().split('T')[0], | |
| type: 'containers', | |
| quantity: amount, | |
| action: 'added', | |
| updatedBy: currentUser | |
| }); | |
| localStorage.setItem('ranaSweetInventoryHistory', JSON.stringify(inventoryHistoryDB)); | |
| updateInventoryDisplay(); | |
| renderInventoryHistory(); | |
| document.getElementById('addContainers').value = '0'; | |
| }); | |
| } | |
| // Update inventory display | |
| function updateInventoryDisplay() { | |
| document.getElementById('currentChhena').textContent = `${inventoryDB.chhena} kg`; | |
| document.getElementById('currentSugar').textContent = `${inventoryDB.sugar} kg`; | |
| document.getElementById('currentContainers').textContent = inventoryDB.containers; | |
| } | |
| // Render inventory history | |
| function renderInventoryHistory() { | |
| const historyTable = document.getElementById('inventoryHistoryTable'); | |
| historyTable.innerHTML = ''; | |
| if (inventoryHistoryDB.length === 0) { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = '<td colspan="5" class="py-4 text-center text-gray-500">No inventory history</td>'; | |
| historyTable.appendChild(row); | |
| return; | |
| } | |
| // Sort by date (descending) | |
| const sortedHistory = [...inventoryHistoryDB].sort((a, b) => new Date(b.date) - new Date(a.date)); | |
| sortedHistory.forEach(item => { | |
| const row = document.createElement('tr'); | |
| row.className = 'border-b hover:bg-gray-50'; | |
| row.innerHTML = ` | |
| <td class="py-2">${formatDate(item.date)}</td> | |
| <td class="py-2">${item.type.charAt(0).toUpperCase() + item.type.slice(1)}</td> | |
| <td class="py-2">${item.quantity}</td> | |
| <td class="py-2">${item.action}</td> | |
| <td class="py-2">${item.updatedBy}</td> | |
| `; | |
| historyTable.appendChild(row); | |
| }); | |
| } | |
| // Menu functionality (same as before) | |
| function initMenu() { | |
| const menuToggle = document.getElementById('menuToggle'); | |
| const closeMenu = document.getElementById('closeMenu'); | |
| const sidebar = document.querySelector('.sidebar'); | |
| const tabLinks = document.querySelectorAll('.tab-link'); | |
| menuToggle.addEventListener('click', function() { | |
| sidebar.classList.add('active'); | |
| }); | |
| closeMenu.addEventListener('click', function() { | |
| sidebar.classList.remove('active'); | |
| }); | |
| tabLinks.forEach(link => { | |
| link.addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| const tabId = this.getAttribute('data-tab'); | |
| document.querySelectorAll('.tab-content').forEach(tab => { | |
| tab.classList.remove('active'); | |
| }); | |
| document.getElementById(tabId).classList.add('active'); | |
| tabLinks.forEach(link => { | |
| link.classList.remove('bg-amber-700'); | |
| }); | |
| this.classList.add('bg-amber-700'); | |
| if (window.innerWidth <= 768) { | |
| sidebar.classList.remove('active'); | |
| } | |
| if (tabId === 'orders') renderAllOrders(); | |
| if (tabId === 'payments') { | |
| renderPaymentDue(); | |
| renderPaymentHistory(); | |
| } | |
| if (tabId === 'suppliers') renderSuppliers(); | |
| if (tabId === 'inventory') { | |
| updateInventoryDisplay(); | |
| renderInventoryHistory(); | |
| } | |
| }); | |
| }); | |
| } | |
| // Sweet selection functionality (same as before) | |
| function initSweetSelection() { | |
| const categoryBtns = document.querySelectorAll('.sweet-category-btn'); | |
| categoryBtns.forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const category = this.getAttribute('data-category'); | |
| categoryBtns.forEach(b => { | |
| b.classList.remove('bg-amber-600', 'text-white'); | |
| b.classList.add('bg-gray-200'); | |
| }); | |
| this.classList.remove('bg-gray-200'); | |
| this.classList.add('bg-amber-600', 'text-white'); | |
| document.querySelectorAll('.sweet-options').forEach(opt => { | |
| opt.classList.add('hidden'); | |
| }); | |
| document.getElementById(`${category}-options`).classList.remove('hidden'); | |
| }); | |
| }); | |
| document.addEventListener('click', function(e) { | |
| if (e.target.classList.contains('increment-btn')) { | |
| const input = e.target.parentElement.querySelector('.quantity'); | |
| input.value = parseInt(input.value) + 1; | |
| updateOrderSummary(); | |
| } | |
| if (e.target.classList.contains('decrement-btn')) { | |
| const input = e.target.parentElement.querySelector('.quantity'); | |
| if (parseInt(input.value) > 0) { | |
| input.value = parseInt(input.value) - 1; | |
| updateOrderSummary(); | |
| } | |
| } | |
| }); | |
| document.querySelectorAll('.quantity').forEach(input => { | |
| input.addEventListener('change', updateOrderSummary); | |
| }); | |
| } | |
| // Order form functionality (same as before) | |
| function initOrderForm() { | |
| const advancePayment = document.getElementById('advancePayment'); | |
| advancePayment.addEventListener('input', updateOrderSummary); | |
| document.getElementById('submitOrder').addEventListener('click', submitOrder); | |
| } | |
| // Update order summary (same as before) | |
| function updateOrderSummary() { | |
| const summaryTable = document.getElementById('orderSummaryTable'); | |
| summaryTable.innerHTML = ''; | |
| let totalAmount = 0; | |
| let totalChhena = 0; | |
| let containersNeeded = 0; | |
| const selectedItems = []; | |
| document.querySelectorAll('.sweet-item').forEach(item => { | |
| const quantity = parseInt(item.querySelector('.quantity').value); | |
| if (quantity > 0) { | |
| const type = item.getAttribute('data-type'); | |
| const price = parseInt(item.getAttribute('data-price')); | |
| const chhenaPerUnit = sweetTypes[type][price].chhena; | |
| const containerCapacity = sweetTypes[type][price].containerCapacity; | |
| const itemTotal = quantity * price; | |
| const itemChhena = quantity * chhenaPerUnit; | |
| const itemContainers = Math.ceil(quantity / containerCapacity); | |
| selectedItems.push({ | |
| type, | |
| price, | |
| quantity, | |
| itemTotal, | |
| itemChhena, | |
| itemContainers | |
| }); | |
| totalAmount += itemTotal; | |
| totalChhena += itemChhena; | |
| containersNeeded += itemContainers; | |
| } | |
| }); | |
| selectedItems.forEach(item => { | |
| const row = document.createElement('tr'); | |
| row.className = 'border-b'; | |
| row.innerHTML = ` | |
| <td class="py-2">${item.type.charAt(0).toUpperCase() + item.type.slice(1)} ₹${item.price}</td> | |
| <td class="py-2">₹${item.price}</td> | |
| <td class="py-2">${item.quantity}</td> | |
| <td class="py-2">₹${item.itemTotal}</td> | |
| <td class="py-2">${item.itemChhena}g</td> | |
| `; | |
| summaryTable.appendChild(row); | |
| }); | |
| const advance = parseFloat(document.getElementById('advancePayment').value) || 0; | |
| const balance = totalAmount - advance; | |
| document.getElementById('totalAmount').textContent = `₹${totalAmount}`; | |
| document.getElementById('advanceDisplay').textContent = `₹${advance}`; | |
| document.getElementById('balanceDue').textContent = `₹${balance}`; | |
| document.getElementById('totalChhena').textContent = totalChhena; | |
| document.getElementById('containersNeeded').textContent = containersNeeded; | |
| } | |
| // Submit new order (same as before) | |
| function submitOrder() { | |
| const customerName = document.getElementById('customerName').value.trim(); | |
| const customerPhone = document.getElementById('customerPhone').value.trim(); | |
| const deliveryDate = document.getElementById('deliveryDate').value; | |
| const advancePayment = parseFloat(document.getElementById('advancePayment').value) || 0; | |
| if (!customerName || !customerPhone || !deliveryDate) { | |
| alert('Please fill in all required fields'); | |
| return; | |
| } | |
| const orderItems = []; | |
| let totalAmount = 0; | |
| let totalChhena = 0; | |
| let containersNeeded = 0; | |
| document.querySelectorAll('.sweet-item').forEach(item => { | |
| const quantity = parseInt(item.querySelector('.quantity').value); | |
| if (quantity > 0) { | |
| const type = item.getAttribute('data-type'); | |
| const price = parseInt(item.getAttribute('data-price')); | |
| const chhenaPerUnit = sweetTypes[type][price].chhena; | |
| const containerCapacity = sweetTypes[type][price].containerCapacity; | |
| const itemTotal = quantity * price; | |
| const itemChhena = quantity * chhenaPerUnit; | |
| const itemContainers = Math.ceil(quantity / containerCapacity); | |
| orderItems.push({ | |
| type, | |
| price, | |
| quantity, | |
| itemTotal, | |
| itemChhena, | |
| itemContainers | |
| }); | |
| totalAmount += itemTotal; | |
| totalChhena += itemChhena; | |
| containersNeeded += itemContainers; | |
| } | |
| }); | |
| if (orderItems.length === 0) { | |
| alert('Please select at least one sweet item'); | |
| return; | |
| } | |
| const orderId = 'ORD-' + Date.now().toString().slice(-6); | |
| const newOrder = { | |
| id: orderId, | |
| customerName, | |
| customerPhone, | |
| deliveryDate, | |
| orderDate: new Date().toISOString().split('T')[0], | |
| items: orderItems, | |
| totalAmount, | |
| advancePayment, | |
| balance: totalAmount - advancePayment, | |
| containersNeeded, | |
| totalChhena, | |
| status: 'pending' | |
| }; | |
| ordersDB.push(newOrder); | |
| localStorage.setItem('ranaSweetOrders', JSON.stringify(ordersDB)); | |
| document.getElementById('customerName').value = ''; | |
| document.getElementById('customerPhone').value = ''; | |
| document.getElementById('advancePayment').value = '0'; | |
| document.querySelectorAll('.quantity').forEach(input => { | |
| input.value = '0'; | |
| }); | |
| updateOrderSummary(); | |
| updateDashboard(); | |
| renderAllOrders(); | |
| alert(`Order ${orderId} created successfully!`); | |
| document.querySelector('.tab-link[data-tab="orders"]').click(); | |
| } | |
| // Render all orders (same as before) | |
| function renderAllOrders() { | |
| const ordersTable = document.getElementById('allOrdersTable'); | |
| ordersTable.innerHTML = ''; | |
| if (ordersDB.length === 0) { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = '<td colspan="11" class="py-4 text-center text-gray-500">No orders found</td>'; | |
| ordersTable.appendChild(row); | |
| return; | |
| } | |
| const sortedOrders = [...ordersDB].sort((a, b) => new Date(a.deliveryDate) - new Date(b.deliveryDate)); | |
| sortedOrders.forEach(order => { | |
| const row = document.createElement('tr'); | |
| row.className = 'border-b hover:bg-gray-50'; | |
| row.innerHTML = ` | |
| <td class="py-2">${order.id}</td> | |
| <td class="py-2">${order.customerName}</td> | |
| <td class="py-2">${order.customerPhone}</td> | |
| <td class="py-2">${order.items.length} items</td> | |
| <td class="py-2">₹${order.totalAmount}</td> | |
| <td class="py-2">₹${order.advancePayment}</td> | |
| <td class="py-2">₹${order.balance}</td> | |
| <td class="py-2">${formatDate(order.deliveryDate)}</td> | |
| <td class="py-2">${order.containersNeeded}</td> | |
| <td class="py-2"> | |
| <span class="px-2 py-1 rounded-full text-xs ${order.status === 'pending' ? 'bg-yellow-100 text-yellow-800' : 'bg-green-100 text-green-800'}"> | |
| ${order.status} | |
| </span> | |
| </td> | |
| <td class="py-2"> | |
| <button class="view-order-btn px-2 py-1 bg-blue-100 text-blue-800 rounded text-sm" data-order-id="${order.id}"> | |
| <i class="fas fa-eye mr-1"></i>View | |
| </button> | |
| </td> | |
| `; | |
| ordersTable.appendChild(row); | |
| }); | |
| document.querySelectorAll('.view-order-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const orderId = this.getAttribute('data-order-id'); | |
| showOrderDetails(orderId); | |
| }); | |
| }); | |
| } | |
| // Show order details modal (same as before) | |
| function showOrderDetails(orderId) { | |
| const order = ordersDB.find(o => o.id === orderId); | |
| if (!order) return; | |
| document.getElementById('modalOrderId').textContent = order.id; | |
| document.getElementById('modalCustomerName').textContent = order.customerName; | |
| document.getElementById('modalCustomerPhone').textContent = order.customerPhone; | |
| document.getElementById('modalDeliveryDate').textContent = `Delivery: ${formatDate(order.deliveryDate)}`; | |
| document.getElementById('modalOrderTotal').textContent = `₹${order.totalAmount}`; | |
| document.getElementById('modalOrderPaid').textContent = `₹${order.advancePayment}`; | |
| document.getElementById('modalOrderBalance').textContent = `₹${order.balance}`; | |
| document.getElementById('modalContainers').textContent = order.containersNeeded; | |
| document.getElementById('modalTotalChhena').textContent = order.totalChhena; | |
| const itemsTable = document.getElementById('modalOrderItems'); | |
| itemsTable.innerHTML = ''; | |
| order.items.forEach(item => { | |
| const row = document.createElement('tr'); | |
| row.className = 'border-b'; | |
| row.innerHTML = ` | |
| <td class="py-2">${item.type.charAt(0).toUpperCase() + item.type.slice(1)} ₹${item.price}</td> | |
| <td class="py-2">₹${item.price}</td> | |
| <td class="py-2">${item.quantity}</td> | |
| <td class="py-2">₹${item.itemTotal}</td> | |
| <td class="py-2">${item.itemChhena}g</td> | |
| `; | |
| itemsTable.appendChild(row); | |
| }); | |
| document.getElementById('markDeliveredBtn').setAttribute('data-order-id', order.id); | |
| document.getElementById('callSupplierBtn').setAttribute('data-order-id', order.id); | |
| document.getElementById('deleteOrderBtn').setAttribute('data-order-id', order.id); | |
| document.getElementById('addPaymentBtn').setAttribute('data-order-id', order.id); | |
| document.getElementById('orderDetailsModal').classList.remove('hidden'); | |
| } | |
| // Initialize modals (same as before) | |
| function initModals() { | |
| const orderModal = document.getElementById('orderDetailsModal'); | |
| document.getElementById('closeOrderModal').addEventListener('click', function() { | |
| orderModal.classList.add('hidden'); | |
| }); | |
| document.getElementById('markDeliveredBtn').addEventListener('click', function() { | |
| const orderId = this.getAttribute('data-order-id'); | |
| const orderIndex = ordersDB.findIndex(o => o.id === orderId); | |
| if (orderIndex !== -1) { | |
| ordersDB[orderIndex].status = 'delivered'; | |
| localStorage.setItem('ranaSweetOrders', JSON.stringify(ordersDB)); | |
| orderModal.classList.add('hidden'); | |
| renderAllOrders(); | |
| updateDashboard(); | |
| } | |
| }); | |
| document.getElementById('deleteOrderBtn').addEventListener('click', function() { | |
| if (confirm('Are you sure you want to delete this order?')) { | |
| const orderId = this.getAttribute('data-order-id'); | |
| ordersDB = ordersDB.filter(o => o.id !== orderId); | |
| localStorage.setItem('ranaSweetOrders', JSON.stringify(ordersDB)); | |
| orderModal.classList.add('hidden'); | |
| renderAllOrders(); | |
| updateDashboard(); | |
| } | |
| }); | |
| document.getElementById('addPaymentBtn').addEventListener('click', function() { | |
| const orderId = this.getAttribute('data-order-id'); | |
| const amount = parseFloat(document.getElementById('addPaymentAmount').value); | |
| if (isNaN(amount) || amount <= 0) { | |
| alert('Please enter a valid amount'); | |
| return; | |
| } | |
| const orderIndex = ordersDB.findIndex(o => o.id === orderId); | |
| if (orderIndex !== -1) { | |
| const order = ordersDB[orderIndex]; | |
| const newAdvance = order.advancePayment + amount; | |
| ordersDB[orderIndex].advancePayment = newAdvance; | |
| ordersDB[orderIndex].balance = order.totalAmount - newAdvance; | |
| localStorage.setItem('ranaSweetOrders', JSON.stringify(ordersDB)); | |
| const payment = { | |
| date: new Date().toISOString().split('T')[0], | |
| orderId, | |
| customerName: order.customerName, | |
| amount, | |
| method: 'cash', | |
| receivedBy: currentUser | |
| }; | |
| paymentHistoryDB.push(payment); | |
| localStorage.setItem('ranaSweetPaymentHistory', JSON.stringify(paymentHistoryDB)); | |
| document.getElementById('modalOrderPaid').textContent = `₹${newAdvance}`; | |
| document.getElementById('modalOrderBalance').textContent = `₹${order.totalAmount - newAdvance}`; | |
| document.getElementById('addPaymentAmount').value = ''; | |
| renderPaymentDue(); | |
| renderPaymentHistory(); | |
| } | |
| }); | |
| document.getElementById('callSupplierBtn').addEventListener('click', function() { | |
| const orderId = this.getAttribute('data-order-id'); | |
| const order = ordersDB.find(o => o.id === orderId); | |
| if (order) { | |
| if (suppliersDB.length === 0) { | |
| alert('Please add a supplier first'); | |
| document.querySelector('.tab-link[data-tab="suppliers"]').click(); | |
| orderModal.classList.add('hidden'); | |
| return; | |
| } | |
| const supplier = suppliersDB[0]; | |
| const deliveryDate = new Date(order.deliveryDate); | |
| const callDate = new Date(deliveryDate); | |
| callDate.setDate(callDate.getDate() - 2); | |
| const call = { | |
| date: callDate.toISOString().split('T')[0], | |
| supplierId: supplier.id, | |
| supplierName: supplier.name, | |
| chhena: order.totalChhena / 1000, | |
| sugar: (order.totalChhena * sugarRatio) / 1000, | |
| deliveryDate: order.deliveryDate, | |
| orderId, | |
| status: 'pending' | |
| }; | |
| supplierCallHistoryDB.push(call); | |
| localStorage.setItem('ranaSweetSupplierCallHistory', JSON.stringify(supplierCallHistoryDB)); | |
| alert(`Call scheduled to ${supplier.name} on ${formatDate(call.date)} for ${call.chhena}kg chhena and ${call.sugar}kg sugar`); | |
| renderSupplierCallHistory(); | |
| updateDashboard(); | |
| } | |
| }); | |
| const supplierModal = document.getElementById('supplierModal'); | |
| document.getElementById('addSupplierBtn').addEventListener('click', function() { | |
| document.getElementById('supplierModalTitle').textContent = 'Add New Supplier'; | |
| document.getElementById('supplierName').value = ''; | |
| document.getElementById('supplierPhone').value = ''; | |
| document.getElementById('supplierChhenaRate').value = '0'; | |
| document.getElementById('supplierSugarRate').value = '0'; | |
| supplierModal.classList.remove('hidden'); | |
| }); | |
| document.getElementById('closeSupplierModal').addEventListener('click', function() { | |
| supplierModal.classList.add('hidden'); | |
| }); | |
| document.getElementById('cancelSupplier').addEventListener('click', function() { | |
| supplierModal.classList.add('hidden'); | |
| }); | |
| document.getElementById('saveSupplier').addEventListener('click', function() { | |
| const name = document.getElementById('supplierName').value.trim(); | |
| const phone = document.getElementById('supplierPhone').value.trim(); | |
| const chhenaRate = parseFloat(document.getElementById('supplierChhenaRate').value) || 0; | |
| const sugarRate = parseFloat(document.getElementById('supplierSugarRate').value) || 0; | |
| if (!name || !phone) { | |
| alert('Please fill in all required fields'); | |
| return; | |
| } | |
| const supplierId = 'SUP-' + Date.now().toString().slice(-6); | |
| const newSupplier = { | |
| id: supplierId, | |
| name, | |
| phone, | |
| chhenaRate, | |
| sugarRate, | |
| pendingOrders: 0, | |
| completedOrders: 0, | |
| lastCall: null | |
| }; | |
| suppliersDB.push(newSupplier); | |
| localStorage.setItem('ranaSweetSuppliers', JSON.stringify(suppliersDB)); | |
| supplierModal.classList.add('hidden'); | |
| renderSuppliers(); | |
| }); | |
| } | |
| // Initialize calendar (same as before) | |
| function initCalendar() { | |
| const calendarEl = document.getElementById('deliveryCalendar'); | |
| const calendar = new FullCalendar.Calendar(calendarEl, { | |
| initialView: 'dayGridMonth', | |
| events: ordersDB.map(order => ({ | |
| title: `${order.customerName} - ₹${order.totalAmount}`, | |
| start: order.deliveryDate, | |
| backgroundColor: order.status === 'delivered' ? '#10B981' : '#F59E0B', | |
| borderColor: order.status === 'delivered' ? '#10B981' : '#F59E0B', | |
| extendedProps: { | |
| orderId: order.id | |
| } | |
| })), | |
| eventClick: function(info) { | |
| const orderId = info.event.extendedProps.orderId; | |
| showOrderDetails(orderId); | |
| } | |
| }); | |
| calendar.render(); | |
| renderUpcomingSupplierCalls(); | |
| } | |
| // Render upcoming supplier calls (same as before) | |
| function renderUpcomingSupplierCalls() { | |
| const callsTable = document.getElementById('supplierCallsTable'); | |
| callsTable.innerHTML = ''; | |
| const today = new Date().toISOString().split('T')[0]; | |
| const upcomingCalls = supplierCallHistoryDB.filter(call => call.date >= today); | |
| if (upcomingCalls.length === 0) { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = '<td colspan="6" class="py-4 text-center text-gray-500">No upcoming supplier calls</td>'; | |
| callsTable.appendChild(row); | |
| return; | |
| } | |
| const sortedCalls = [...upcomingCalls].sort((a, b) => new Date(a.date) - new Date(b.date)); | |
| sortedCalls.forEach(call => { | |
| const row = document.createElement('tr'); | |
| row.className = 'border-b hover:bg-gray-50'; | |
| row.innerHTML = ` | |
| <td class="py-2">${call.supplierName}</td> | |
| <td class="py-2">${formatDate(call.date)}</td> | |
| <td class="py-2">${call.chhena} kg</td> | |
| <td class="py-2">${call.sugar} kg</td> | |
| <td class="py-2">${call.orderId}</td> | |
| <td class="py-2"> | |
| <button class="call-supplier-btn px-2 py-1 bg-green-100 text-green-800 rounded text-sm" data-supplier-id="${call.supplierId}"> | |
| <i class="fas fa-phone mr-1"></i>Call Now | |
| </button> | |
| </td> | |
| `; | |
| callsTable.appendChild(row); | |
| }); | |
| document.querySelectorAll('.call-supplier-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const supplierId = this.getAttribute('data-supplier-id'); | |
| const supplier = suppliersDB.find(s => s.id === supplierId); | |
| if (supplier) { | |
| alert(`Calling supplier ${supplier.name} at ${supplier.phone}`); | |
| // In a real app, this would initiate a phone call | |
| } | |
| }); | |
| }); | |
| } | |
| // Render suppliers (same as before) | |
| function renderSuppliers() { | |
| const suppliersTable = document.getElementById('suppliersTable'); | |
| suppliersTable.innerHTML = ''; | |
| if (suppliersDB.length === 0) { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = '<td colspan="7" class="py-4 text-center text-gray-500">No suppliers found</td>'; | |
| suppliersTable.appendChild(row); | |
| return; | |
| } | |
| suppliersDB.forEach(supplier => { | |
| const pendingOrders = supplierCallHistoryDB.filter(call => | |
| call.supplierId === supplier.id && call.status === 'pending').length; | |
| const completedOrders = supplierCallHistoryDB.filter(call => | |
| call.supplierId === supplier.id && call.status === 'completed').length; | |
| const supplierCalls = supplierCallHistoryDB.filter(call => call.supplierId === supplier.id); | |
| const lastCall = supplierCalls.length > 0 ? | |
| supplierCalls[supplierCalls.length - 1].date : 'Never'; | |
| const row = document.createElement('tr'); | |
| row.className = 'border-b hover:bg-gray-50'; | |
| row.innerHTML = ` | |
| <td class="py-2">${supplier.name}</td> | |
| <td class="py-2">${supplier.phone}</td> | |
| <td class="py-2">${pendingOrders}</td> | |
| <td class="py-2">${completedOrders}</td> | |
| <td class="py-2">${lastCall === 'Never' ? 'Never' : formatDate(lastCall)}</td> | |
| <td class="py-2">₹${supplier.chhenaRate}/kg</td> | |
| <td class="py-2"> | |
| <button class="edit-supplier-btn px-2 py-1 bg-blue-100 text-blue-800 rounded text-sm mr-1" data-supplier-id="${supplier.id}"> | |
| <i class="fas fa-edit mr-1"></i>Edit | |
| </button> | |
| <button class="delete-supplier-btn px-2 py-1 bg-red-100 text-red-800 rounded text-sm" data-supplier-id="${supplier.id}"> | |
| <i class="fas fa-trash mr-1"></i>Delete | |
| </button> | |
| </td> | |
| `; | |
| suppliersTable.appendChild(row); | |
| }); | |
| document.querySelectorAll('.edit-supplier-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const supplierId = this.getAttribute('data-supplier-id'); | |
| const supplier = suppliersDB.find(s => s.id === supplierId); | |
| if (supplier) { | |
| document.getElementById('supplierModalTitle').textContent = 'Edit Supplier'; | |
| document.getElementById('supplierName').value = supplier.name; | |
| document.getElementById('supplierPhone').value = supplier.phone; | |
| document.getElementById('supplierChhenaRate').value = supplier.chhenaRate; | |
| document.getElementById('supplierSugarRate').value = supplier.sugarRate; | |
| document.getElementById('saveSupplier').setAttribute('data-supplier-id', supplier.id); | |
| document.getElementById('supplierModal').classList.remove('hidden'); | |
| } | |
| }); | |
| }); | |
| document.querySelectorAll('.delete-supplier-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const supplierId = this.getAttribute('data-supplier-id'); | |
| if (confirm('Are you sure you want to delete this supplier?')) { | |
| suppliersDB = suppliersDB.filter(s => s.id !== supplierId); | |
| localStorage.setItem('ranaSweetSuppliers', JSON.stringify(suppliersDB)); | |
| renderSuppliers(); | |
| } | |
| }); | |
| }); | |
| } | |
| // Render payment due (same as before) | |
| function renderPaymentDue() { | |
| const paymentsTable = document.getElementById('paymentsDueTable'); | |
| paymentsTable.innerHTML = ''; | |
| const pendingPayments = ordersDB.filter(order => order.balance > 0); | |
| if (pendingPayments.length === 0) { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = '<td colspan="8" class="py-4 text-center text-gray-500">No pending payments</td>'; | |
| paymentsTable.appendChild(row); | |
| return; | |
| } | |
| pendingPayments.forEach(order => { | |
| const row = document.createElement('tr'); | |
| row.className = 'border-b hover:bg-gray-50'; | |
| row.innerHTML = ` | |
| <td class="py-2">${order.customerName}</td> | |
| <td class="py-2">${order.customerPhone}</td> | |
| <td class="py-2">${order.id}</td> | |
| <td class="py-2">₹${order.totalAmount}</td> | |
| <td class="py-2">₹${order.advancePayment}</td> | |
| <td class="py-2">₹${order.balance}</td> | |
| <td class="py-2">${formatDate(order.deliveryDate)}</td> | |
| <td class="py-2"> | |
| <button class="add-payment-btn px-2 py-1 bg-green-100 text-green-800 rounded text-sm" data-order-id="${order.id}"> | |
| <i class="fas fa-money-bill-wave mr-1"></i>Add Payment | |
| </button> | |
| </td> | |
| `; | |
| paymentsTable.appendChild(row); | |
| }); | |
| document.querySelectorAll('.add-payment-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const orderId = this.getAttribute('data-order-id'); | |
| showOrderDetails(orderId); | |
| }); | |
| }); | |
| } | |
| // Render payment history (same as before) | |
| function renderPaymentHistory() { | |
| const historyTable = document.getElementById('paymentHistoryTable'); | |
| historyTable.innerHTML = ''; | |
| if (paymentHistoryDB.length === 0) { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = '<td colspan="6" | |
| </html> |