Equipment & Asset Depreciation Calculator
Asset Information
All monetary values are in USD ($).
Depreciation Report
| Year | Annual Depreciation ($) | Accumulated Depreciation ($) | Book Value at Year End ($) |
|---|
Depreciation Method: ${assetDetails.methodName}
`; depreciationTableBody.innerHTML = ''; if (depreciationSchedule.length === 0) { const row = depreciationTableBody.insertRow(); const cell = row.insertCell(); cell.colSpan = 4; cell.textContent = 'No depreciation schedule to display.'; cell.style.textAlign = 'center'; } else { depreciationSchedule.forEach(item => { const row = depreciationTableBody.insertRow(); row.insertCell().setAttribute('data-label', 'Year'); row.cells[0].textContent = item.year; row.insertCell().setAttribute('data-label', 'Annual Depr. ($)'); row.cells[1].textContent = item.annualDepreciation.toFixed(2); row.insertCell().setAttribute('data-label', 'Accum. Depr. ($)'); row.cells[2].textContent = item.accumulatedDepreciation.toFixed(2); row.insertCell().setAttribute('data-label', 'Book Value ($)'); row.cells[3].textContent = item.bookValue.toFixed(2); }); } } downloadPdfBtn.addEventListener('click', function() { if (!assetDetails.name || depreciationSchedule.length === 0) { alert("Please calculate a depreciation schedule first."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); const primaryColor = getComputedStyle(document.documentElement).getPropertyValue('--primary-color').trim(); const accentColor = getComputedStyle(document.documentElement).getPropertyValue('--table-header-bg').trim(); const whiteText = getComputedStyle(document.documentElement).getPropertyValue('--white-text').trim(); const darkText = getComputedStyle(document.documentElement).getPropertyValue('--dark-text').trim(); let YPosition = 15; const leftMargin = 14; doc.setFontSize(18); doc.setTextColor(primaryColor); doc.text("Asset Depreciation Report", doc.internal.pageSize.getWidth() / 2, YPosition, { align: 'center' }); YPosition += 10; doc.setFontSize(12); doc.setTextColor(darkText); YPosition = checkAndAddPage(doc, YPosition); doc.setFont(undefined, 'bold'); doc.text("Asset Details", leftMargin, YPosition); YPosition += 6; doc.setFont(undefined, 'normal'); const details = [ ["Asset Name:", assetDetails.name], ["Acquisition Cost:", `$${assetDetails.cost.toFixed(2)}`], ["Salvage Value:", `$${assetDetails.salvage.toFixed(2)}`], ["Useful Life:", `${assetDetails.life} Years`], ["First Year of Depreciation:", `${assetDetails.firstYear}`], ["Depreciation Method:", assetDetails.methodName] ]; doc.autoTable({ startY: YPosition, body: details, theme: 'plain', styles: { fontSize: 10, cellPadding: 1.5, textColor: darkText }, columnStyles: { 0: { fontStyle: 'bold', cellWidth: 60 } }, tableWidth: 'wrap' }); YPosition = doc.lastAutoTable.finalY + 8; YPosition = checkAndAddPage(doc, YPosition); doc.setFontSize(12); doc.setFont(undefined, 'bold'); doc.setTextColor(accentColor); doc.text("Depreciation Schedule", leftMargin, YPosition); YPosition += 6; const scheduleHeaders = [['Year', 'Annual Depreciation ($)', 'Accumulated Depreciation ($)', 'Book Value at Year End ($)']]; const scheduleBody = depreciationSchedule.map(item => [ item.year, item.annualDepreciation.toFixed(2), item.accumulatedDepreciation.toFixed(2), item.bookValue.toFixed(2) ]); doc.autoTable({ startY: YPosition, head: scheduleHeaders, body: scheduleBody, theme: 'grid', headStyles: { fillColor: accentColor, textColor: whiteText, fontSize: 9 }, styles: { font: 'Arial', fontSize: 8, cellPadding: 1.5, textColor: darkText }, columnStyles: { 0: { halign: 'center', cellWidth: 20 }, 1: { halign: 'right' }, 2: { halign: 'right' }, 3: { halign: 'right' } } }); YPosition = doc.lastAutoTable.finalY + 10; doc.setFontSize(8); doc.setTextColor(100); const generatedDateText = `PDF Generated on: ${formatDateForDisplay(REF_DATE)} ${REF_DATE.toLocaleTimeString()}`; doc.text(generatedDateText, leftMargin, doc.internal.pageSize.height - 10); doc.save(`Depreciation_Schedule_${assetDetails.name.replace(/\s+/g, '_') || 'Asset'}.pdf`); }); function checkAndAddPage(docInstance, currentY) { if (currentY > docInstance.internal.pageSize.height - 30) { // 30mm margin from bottom docInstance.addPage(); return 20; // Reset Y for new page } return currentY; } function formatDateForDisplay(dateObj) { if (!dateObj) return ''; return dateObj.toISOString().split('T')[0]; } // Initial setup updateNavButtons(); // Set default year for firstYearInput if (!firstYearInput.value) { firstYearInput.value = REF_DATE.getFullYear(); } });