Current Operations: ${CONFIG_INPUTS.currentOps.value || 'N/A'}
`;
html += `
Target Operations: ${CONFIG_INPUTS.targetOps.value || 'N/A'}
`;
html += `
Timeframe: ${CONFIG_INPUTS.timeframe.value || 'N/A'}, Additional Employees: ${additionalEmployees}
`;
html += `
New/Expanded Space Required: ${CONFIG_INPUTS.newSpaceRequired.value}
`;
html += `
`;
html += '
Forecasted Costs Breakdown:
';
html += '
| Category | Item | Type | Estimated Cost |
';
if (allCosts.length === 0 && contingencyAmount === 0) {
html += '| No costs entered. |
';
} else {
const groupedByCategory = allCosts.reduce((acc, item) => {
(acc[item.category] = acc[item.category] || []).push(item);
return acc;
}, {});
for (const category in groupedByCategory) {
html += ``;
groupedByCategory[category].forEach(item => {
html += `
|
${item.name} |
${item.type} |
${currency}${item.amount.toFixed(2)} |
`;
});
}
html += `| Subtotal of Direct Forecasted Costs: | ${currency}${subtotalDirectCosts.toFixed(2)} |
`;
html += `| Contingency (${contingencyType === 'percentage' ? contingencyValue + '%' : 'Fixed'}): | ${currency}${contingencyAmount.toFixed(2)} |
`;
}
html += `| GRAND TOTAL ESTIMATED SCALING COST: | ${currency}${grandTotal.toFixed(2)} |
`;
html += '
';
if (additionalEmployees > 0) {
html += `
Estimated Cost Per Additional Employee: ${currency}${(grandTotal / additionalEmployees).toFixed(2)}
`;
}
summaryOutput.innerHTML = html;
document.getElementById('bscf-download-pdf').disabled = allCosts.length === 0 && contingencyAmount === 0;
}
// PDF Download
document.getElementById('bscf-download-pdf').addEventListener('click', function () {
if (typeof jspdf === 'undefined' || typeof jspdf.jsPDF === 'undefined') {
alert('Error: jsPDF library is not loaded.'); return;
}
const { jsPDF } = jspdf;
const doc = new jsPDF('p');
const currency = CONFIG_INPUTS.currencySymbol.value || '$';
const additionalEmployees = getNum(CONFIG_INPUTS.additionalEmployees.value);
const primaryColor = getComputedStyle(document.documentElement).getPropertyValue('--bscf-primary-color').trim();
const secondaryColor = getComputedStyle(document.documentElement).getPropertyValue('--bscf-secondary-color').trim();
const textColor = getComputedStyle(document.documentElement).getPropertyValue('--bscf-text-color').trim();
const buttonTextColor = getComputedStyle(document.documentElement).getPropertyValue('--bscf-button-text-color').trim();
doc.setFontSize(18);
doc.setTextColor(primaryColor);
doc.text('Business Scaling Cost Forecast', doc.internal.pageSize.getWidth() / 2, 20, { align: 'center' });
doc.setFontSize(12);
doc.setTextColor(textColor);
let lastY = 30;
doc.text(`Business Name: ${CONFIG_INPUTS.businessName.value || 'N/A'}`, 14, lastY); lastY += 7;
doc.text(`Initiative Name: ${CONFIG_INPUTS.initiativeName.value || 'N/A'}`, 14, lastY); lastY += 7;
doc.text(`Current Ops: ${CONFIG_INPUTS.currentOps.value || 'N/A'}`, 14, lastY); lastY += 7;
doc.text(`Target Ops: ${CONFIG_INPUTS.targetOps.value || 'N/A'}`, 14, lastY); lastY += 7;
doc.text(`Timeframe: ${CONFIG_INPUTS.timeframe.value || 'N/A'}`, 14, lastY); lastY += 7;
doc.text(`Additional Employees: ${additionalEmployees}`, 14, lastY); lastY += 7;
doc.text(`New/Expanded Space: ${CONFIG_INPUTS.newSpaceRequired.value}`, 14, lastY); lastY += 7;
doc.text(`Currency: ${currency}`, 14, lastY); lastY += 10;
const allCostsPdf = [];
let subtotalDirectCostsPdf = 0;
// Re-collect for PDF
document.querySelectorAll('#costs .bscf-cost-category-section').forEach(section => {
const isSpaceSection = section.id === 'bscf-real-estate-section';
const spaceRequired = CONFIG_INPUTS.newSpaceRequired.value === 'Yes';
if (isSpaceSection && !spaceRequired) return;
if (section.style.display === 'block' || section.classList.contains('bscf-visible')) {
section.querySelectorAll('.bscf-cost-item').forEach(input => {
const cost = getNum(input.value);
if (cost > 0) {
let costType = "Investment/Setup";
if (input.id.includes("initial-salaries") || input.id.includes("marketing-budget") || input.id.includes("working-capital") || input.id.includes("financing-costs") || (input.dataset.category === "Tech & Infrastructure" && (input.id.includes("sw-licenses") || input.id.includes("server-cloud") || input.id.includes("support-security"))) || (input.dataset.category === "Sales & Marketing Scaling") ) { costType = "Ramp-up Operating"; }
allCostsPdf.push({ category: input.dataset.category, name: input.dataset.itemName, type: costType, amount: cost });
subtotalDirectCostsPdf += cost;
}
});
}
});
document.querySelectorAll('.bscf-custom-cost-item').forEach(item => {
const name = item.querySelector('.bscf-custom-name').value || 'Custom Cost';
const amount = getNum(item.querySelector('.bscf-custom-amount').value);
const type = item.querySelector('.bscf-custom-cost-type').value;
if (amount > 0) {
allCostsPdf.push({ category: 'Custom Scaling Costs', name, type, amount });
subtotalDirectCostsPdf += amount;
}
});
const contingencyTypePdf = CONFIG_INPUTS.contingencyType.value;
const contingencyValuePdf = getNum(CONFIG_INPUTS.contingencyValue.value);
let contingencyAmountPdf = (contingencyTypePdf === 'percentage') ? subtotalDirectCostsPdf * (contingencyValuePdf / 100) : contingencyValuePdf;
const grandTotalPdf = subtotalDirectCostsPdf + contingencyAmountPdf;
const tableBody = [];
const groupedByCategoryPdf = allCostsPdf.reduce((acc, item) => {
(acc[item.category] = acc[item.category] || []).push(item);
return acc;
}, {});
for (const category in groupedByCategoryPdf) {
tableBody.push([{ content: category, colSpan: 3, styles: { fontStyle: 'bold', fillColor: '#f0f0f0' } }]);
groupedByCategoryPdf[category].forEach(item => {
tableBody.push([item.name, item.type, `${currency}${item.amount.toFixed(2)}`]);
});
}
tableBody.push([
{ content: 'Subtotal of Direct Costs:', colSpan: 2, styles: { halign: 'right', fontStyle: 'bold'} },
{ content: `${currency}${subtotalDirectCostsPdf.toFixed(2)}`, styles: { halign: 'right', fontStyle: 'bold' } }
]);
tableBody.push([
{ content: `Contingency (${contingencyTypePdf === 'percentage' ? contingencyValuePdf + '%' : 'Fixed'}):`, colSpan: 2, styles: { halign: 'right', fontStyle: 'bold'} },
{ content: `${currency}${contingencyAmountPdf.toFixed(2)}`, styles: { halign: 'right', fontStyle: 'bold' } }
]);
tableBody.push([
{ content: 'GRAND TOTAL:', colSpan: 2, styles: { halign: 'right', fontStyle: 'bold', fillColor: primaryColor, textColor: buttonTextColor } },
{ content: `${currency}${grandTotalPdf.toFixed(2)}`, styles: { halign: 'right', fontStyle: 'bold', fillColor: primaryColor, textColor: buttonTextColor } }
]);
doc.autoTable({
startY: lastY,
head: [['Cost Category/Item', 'Type', 'Estimated Cost']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: secondaryColor, textColor: buttonTextColor, fontSize: 9 },
styles: { fontSize: 8, cellPadding: 2 },
columnStyles: { 2: { halign: 'right' } },
didDrawCell: (data) => {
if (data.cell.raw && data.cell.raw.colSpan === 3) { /* Category Header */ }
}
});
lastY = doc.lastAutoTable.finalY + 10;
doc.setFontSize(10);
doc.setTextColor(textColor);
if (additionalEmployees > 0) {
doc.text(`Estimated Cost Per Additional Employee: ${currency}${(grandTotalPdf / additionalEmployees).toFixed(2)}`, 14, lastY);
}
doc.save(`Business_Scaling_Forecast_${CONFIG_INPUTS.initiativeName.value.replace(/\s+/g, '_') || 'Report'}.pdf`);
});
// Initial setup
checkEmptyState(COST_CONTAINERS.customCosts, 'bscf-no-items-text');
toggleRealEstateSection();
toggleContingencyInputType();
showTab(0);
updateAllCurrencyPrefixes();
});