getFinancialsQuarters();
$lastQuarterEarnings = $quarterEarnings[0];
$quarterEarningsBalance = $fundamentals->getFinancialsQuartersBalance();
$quarterEarningsCashflow = $fundamentals->getFinancialsQuartersCashflow();
$annualEarnings = $fundamentals->getFinancialsAnnuals();
$annualEarningsBalance = $fundamentals->getFinancialsAnnualsBalance();
$annualEarningsCashflow = $fundamentals->getFinancialsAnnualsCashflow();
$QuarterGrowth = $fundamentals->getFinancialsQuartersGrowth();
$YearGrowth = $fundamentals->getFinancialsAnnualsGrowth();
$FinancialScore = $fundamentals->getFinancialScore();
$historicData = $dataBase->select_HistoricalData($ticker, 1000);
// Define detailed income statement metrics with categories
$metricCategories = [
'Revenue & Cost' => [
'revenue' => 'Total Revenue',
'costOfRevenue' => 'Cost of Revenue',
'grossProfit' => 'Gross Profit',
'grossProfitRatio' => 'Gross Margin %'
],
'Operating Expenses' => [
'ResearchAndDevelopmentExpenses' => 'R&D Expenses',
'sellingGeneralAndAdministrativeExpenses' => 'SG&A Expenses',
'otherExpenses' => 'Other Operating Expenses',
'operatingExpenses' => 'Total Operating Expenses'
],
'Operating Performance' => [
'operatingIncome' => 'Operating Income',
'operatingIncomeRatio' => 'Operating Margin %',
'ebitda' => 'EBITDA',
'EBITDARatio' => 'EBITDA Margin %'
],
'Other Income/Expenses' => [
'interestExpense' => 'Interest Expense',
'totalOtherIncomeExpensesNet' => 'Other Income/Expenses Net',
'incomeBeforeTax' => 'Income Before Tax',
'incomeTaxExpense' => 'Income Tax Expense'
],
'Net Performance' => [
'netIncome' => 'Net Income',
'netIncomeRatio' => 'Net Margin %',
'eps' => 'EPS',
'EPSDiluted' => 'Diluted EPS'
]
];
// Define balance sheet categories and metrics
$balanceSheetCategories = [
'Assets' => [
'Current Assets' => [
'cashAndCashEquivalents' => 'Cash & Cash Equivalents',
'shortTermInvestments' => 'Short Term Investments',
'netReceivables' => 'Net Receivables',
'inventory' => 'Inventory',
'otherCurrentAssets' => 'Other Current Assets',
'totalCurrentAssets' => 'Total Current Assets'
],
'Non-Current Assets' => [
'propertyPlantEquipmentNet' => 'Property, Plant & Equipment (Net)',
'longTermInvestments' => 'Long Term Investments',
'taxAssets' => 'Tax Assets',
'otherNonCurrentAssets' => 'Other Non-Current Assets',
'totalNonCurrentAssets' => 'Total Non-Current Assets'
],
'Total Assets' => [
'totalAssets' => 'Total Assets'
]
],
'Liabilities' => [
'Current Liabilities' => [
'accountPayables' => 'Accounts Payable',
'shortTermDebt' => 'Short Term Debt',
'taxPayables' => 'Tax Payables',
'deferredRevenue' => 'Deferred Revenue',
'otherCurrentLiabilities' => 'Other Current Liabilities',
'totalCurrentLiabilities' => 'Total Current Liabilities'
],
'Non-Current Liabilities' => [
'longTermDebt' => 'Long Term Debt',
'otherNonCurrentLiabilities' => 'Other Non-Current Liabilities',
'totalNonCurrentLiabilities' => 'Total Non-Current Liabilities'
],
'Total Liabilities' => [
'totalLiabilities' => 'Total Liabilities'
]
],
'Shareholders Equity' => [
'Equity Components' => [
'commonStock' => 'Common Stock',
'retainedEarnings' => 'Retained Earnings',
'accumulatedOtherComprehensiveIncomeLoss' => 'Accumulated Other Comprehensive Income/Loss',
'totalStockholdersEquity' => 'Total Shareholders Equity'
]
],
'Key Metrics' => [
'Balance Check' => [
'totalLiabilitiesAndStockholdersEquity' => 'Total Liabilities & Equity',
'totalDebt' => 'Total Debt',
'netDebt' => 'Net Debt'
]
]
];
// Define cash flow statement categories and metrics
$cashFlowCategories = [
'Operating Activities' => [
'Core Operations' => [
'netIncome' => 'Net Income',
'depreciationAndAmortization' => 'Depreciation & Amortization',
'stockBasedCompensation' => 'Stock Based Compensation'
],
'Working Capital Changes' => [
'accountsReceivables' => 'Change in Accounts Receivable',
'inventory' => 'Change in Inventory',
'accountsPayables' => 'Change in Accounts Payable',
'otherWorkingCapital' => 'Other Working Capital Changes',
'changeInWorkingCapital' => 'Total Working Capital Change'
],
'Other Operating' => [
'otherNonCashItems' => 'Other Non-Cash Items',
'netCashProvidedByOperatingActivites' => 'Net Cash from Operations'
]
],
'Investing Activities' => [
'Capital Investments' => [
'investmentsInPropertyPlantAndEquipment' => 'Capital Expenditures',
'purchasesOfInvestments' => 'Purchase of Investments',
'salesMaturitiesOfInvestments' => 'Sale of Investments',
'otherInvestingActivites' => 'Other Investing Activities',
'netCashUsedForInvestingActivites' => 'Net Cash from Investing'
]
],
'Financing Activities' => [
'Debt & Equity' => [
'debtRepayment' => 'Debt Repayment',
'commonStockRepurchased' => 'Stock Repurchases',
'dividendsPaid' => 'Dividends Paid',
'otherFinancingActivites' => 'Other Financing Activities',
'netCashUsedProvidedByFinancingActivities' => 'Net Cash from Financing'
]
],
'Cash Position' => [
'Summary' => [
'netChangeInCash' => 'Net Change in Cash',
'cashAtBeginningOfPeriod' => 'Cash at Beginning of Period',
'cashAtEndOfPeriod' => 'Cash at End of Period'
],
'Key Metrics' => [
'operatingCashFlow' => 'Operating Cash Flow',
'capitalExpenditure' => 'Capital Expenditure',
'freeCashFlow' => 'Free Cash Flow'
]
]
];
// Update the income statement metrics structure to match other tables
$incomeStatementCategories = [
'Operating Performance' => [
'Revenue & Profitability' => [
'revenue' => 'Total Revenue',
'costOfRevenue' => 'Cost of Revenue',
'grossProfit' => 'Gross Profit',
'grossProfitRatio' => 'Gross Margin %'
],
'Operating Expenses' => [
'ResearchAndDevelopmentExpenses' => 'R&D Expenses',
'sellingGeneralAndAdministrativeExpenses' => 'SG&A Expenses',
'otherExpenses' => 'Other Operating Expenses',
'operatingExpenses' => 'Total Operating Expenses'
]
],
'Income & Margins' => [
'Operating Results' => [
'operatingIncome' => 'Operating Income',
'operatingIncomeRatio' => 'Operating Margin %',
'ebitda' => 'EBITDA',
'EBITDARatio' => 'EBITDA Margin %'
],
'Net Results' => [
'interestExpense' => 'Interest Expense',
'totalOtherIncomeExpensesNet' => 'Other Income/Expenses Net',
'incomeBeforeTax' => 'Income Before Tax',
'incomeTaxExpense' => 'Income Tax Expense',
'netIncome' => 'Net Income',
'netIncomeRatio' => 'Net Margin %'
]
],
'Per Share Metrics' => [
'Share Performance' => [
'eps' => 'EPS',
'EPSDiluted' => 'Diluted EPS'
]
]
];
?>
Income Statement
Balance Sheet
Cash Flow
';
echo 'Metrics ';
foreach ($annualEarnings as $period) {
echo "{$period->calendarYear} ";
}
echo '
';
foreach ($incomeStatementCategories as $mainCategory => $subCategories) {
echo "{$mainCategory} ";
foreach ($subCategories as $subCategory => $metrics) {
echo "{$subCategory} ";
foreach ($metrics as $key => $label) {
echo "{$label} ";
foreach ($annualEarnings as $period) {
$value = isset($period->$key) ? $period->$key : null;
echo "";
if ($value !== null) {
if (strpos($key, 'Ratio') !== false || strpos($key, 'Margin') !== false) {
// Format as percentage
$formattedValue = number_format($value * 100, 2) . '%';
$class = '';
if ($value > 0.15) $class = 'strong-positive';
elseif ($value > 0.05) $class = 'positive';
elseif ($value < -0.05) $class = 'strong-negative';
elseif ($value < 0) $class = 'negative';
echo "{$formattedValue} ";
} else if (strpos($key, 'eps') !== false || strpos($key, 'EPS') !== false) {
// Format as currency with 2 decimal places
$formattedValue = '$' . number_format($value, 2);
$class = $value > 0 ? 'positive' : ($value < 0 ? 'negative' : '');
echo "{$formattedValue} ";
} else {
// Format large numbers with appropriate suffixes
$formattedValue = formatLargeNumber($value);
$class = '';
if (strpos($key, 'Income') !== false || strpos($key, 'Profit') !== false || strpos($key, 'revenue') !== false) {
$class = $value > 0 ? 'positive' : ($value < 0 ? 'negative' : '');
}
echo "{$formattedValue} ";
}
} else {
echo "N/A";
}
echo " ";
}
echo " ";
}
}
}
echo ' ';
?>
';
echo 'Metrics ';
foreach ($annualEarningsBalance as $period) {
echo "{$period->calendarYear} ";
}
echo '
';
foreach ($balanceSheetCategories as $mainCategory => $subCategories) {
echo "{$mainCategory} ";
foreach ($subCategories as $subCategory => $metrics) {
echo "{$subCategory} ";
foreach ($metrics as $key => $label) {
echo "{$label} ";
foreach ($annualEarningsBalance as $period) {
$value = isset($period->$key) ? $period->$key : null;
echo "";
if ($value !== null) {
// Format large numbers with appropriate suffixes
$formattedValue = formatLargeNumber($value);
$class = '';
if (strpos($key, 'Debt') !== false) {
$class = $value > 0 ? 'negative' : 'positive';
} elseif (strpos($key, 'Equity') !== false || strpos($key, 'Assets') !== false || strpos($key, 'Cash') !== false) {
$class = $value > 0 ? 'positive' : ($value < 0 ? 'negative' : '');
}
echo "{$formattedValue} ";
} else {
echo "N/A";
}
echo " ";
}
echo " ";
}
}
}
echo ' ';
?>
';
echo 'Metrics ';
foreach ($annualEarningsCashflow as $period) {
echo "{$period->calendarYear} ";
}
echo '
';
foreach ($cashFlowCategories as $mainCategory => $subCategories) {
echo "{$mainCategory} ";
foreach ($subCategories as $subCategory => $metrics) {
echo "{$subCategory} ";
foreach ($metrics as $key => $label) {
echo "{$label} ";
foreach ($annualEarningsCashflow as $period) {
$value = isset($period->$key) ? $period->$key : null;
echo "";
if ($value !== null) {
// Format large numbers with appropriate suffixes
$formattedValue = formatLargeNumber($value);
$class = '';
if (strpos($key, 'freeCashFlow') !== false || strpos($key, 'operatingCashFlow') !== false) {
$class = $value > 0 ? 'strong-positive' : ($value < 0 ? 'strong-negative' : '');
} elseif (strpos($key, 'Cash') !== false || strpos($key, 'Income') !== false) {
$class = $value > 0 ? 'positive' : ($value < 0 ? 'negative' : '');
} elseif (strpos($key, 'Expenditure') !== false || strpos($key, 'Repayment') !== false || strpos($key, 'Repurchased') !== false) {
$class = $value < 0 ? 'negative' : '';
}
echo "{$formattedValue} ";
} else {
echo "N/A";
}
echo " ";
}
echo " ";
}
}
}
echo ' ';
?>