function attachAddRowButtons() const addSalesBtn = document.getElementById('addSalesRowBtn'); if (addSalesBtn) addSalesBtn.replaceWith(addSalesBtn.cloneNode(true)); document.getElementById('addSalesRowBtn')?.addEventListener('click', () => salesData.push( product: "New Fuel", liters: 0, rate: 100, amount: 0 ); renderTables(); ); const addExpenseBtn = document.getElementById('addExpenseRowBtn'); if (addExpenseBtn) addExpenseBtn.replaceWith(addExpenseBtn.cloneNode(true)); document.getElementById('addExpenseRowBtn')?.addEventListener('click', () => expensesData.push( date: "New Date", category: "Other", amount: 0 ); renderTables(); ); const addStockBtn = document.getElementById('addStockRowBtn'); if (addStockBtn) addStockBtn.replaceWith(addStockBtn.cloneNode(true)); document.getElementById('addStockRowBtn')?.addEventListener('click', () => stockData.push( product: "New Product", opening: 0, received: 0, sold: 0, closing: 0, unitPrice: 100 ); recomputeStock(); renderTables(); );
let expensesData = [ date: "01-Apr-2026", category: "Electricity", amount: 5500 , date: "05-Apr-2026", category: "Staff Salary", amount: 28500 , date: "10-Apr-2026", category: "Maintenance", amount: 3200 , date: "15-Apr-2026", category: "Misc", amount: 1750 ]; petrol pump accounting in excel sheet download
function getTotalClosingStockValue() return stockData.reduce((sum, st) => sum + (st.closing * st.unitPrice), 0); function attachAddRowButtons() const addSalesBtn = document
// Get total sales sum function getTotalSales() return salesData.reduce((sum, item) => sum + item.amount, 0); document
// Download as Excel (XLS format - HTML table wrapper) function downloadExcel() // Generate full workbook style HTML let exportHtml = ` <html> <head><meta charset="UTF-8"><title>PetrolPump_Accounting.xls</title> <style> th background: #4c8b5e; color: #fff; td border: 1px solid #ccc; </style> </head> <body> <h2>Petrol Pump Financial Statement</h2> <h3>Sales Register</h3> <table border="1">$document.querySelector('#salesTable') ? document.querySelector('#salesTable').outerHTML : ''</table> <h3>Expenses Register</h3> <table border="1">$document.querySelector('#expensesTable') ? document.querySelector('#expensesTable').outerHTML : ''</table> <h3>Stock Management</h3> <table border="1">$document.querySelector('#stockTable') ? document.querySelector('#stockTable').outerHTML : ''</table> <br/> <p><strong>Total Sales:</strong> $getTotalSales().toFixed(2)</p> <p><strong>Total Expenses:</strong> $getTotalExpenses().toFixed(2)</p> <p><strong>Net Profit:</strong> $getNetProfit().toFixed(2)</p> <p><strong>Closing Stock Value:</strong> $getTotalClosingStockValue().toFixed(2)</p> </body></html>`; const blob = new Blob([exportHtml], type: "application/vnd.ms-excel" ); const link = document.createElement('a'); const url = URL.createObjectURL(blob); link.href = url; link.download = "Petrol_Pump_Accounts.xls"; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url);
// Update UI cards function updateCards() document.getElementById("totalSalesVal").innerText = getTotalSales().toFixed(2); document.getElementById("totalExpVal").innerText = getTotalExpenses().toFixed(2); document.getElementById("netProfitVal").innerText = getNetProfit().toFixed(2); document.getElementById("closingStockVal").innerText = getTotalClosingStockValue().toFixed(2);