const App = () => {
// State to hold trial balance data
const [trialBalance, setTrialBalance] = React.useState(null);
const [error, setError] = React.useState(null);
React.useEffect(() => {
// Fetch trial balance data
fetch('/api/reports/trial_balance.php')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (data.error) {
throw new Error(data.error);
}
setTrialBalance(data);
})
.catch(error => {
console.error("Error fetching trial balance:", error);
setError(error.toString());
});
}, []);
return (
Trial Balance
{error &&
Error loading data: {error}
}
{!trialBalance && !error &&
Loading...
}
{trialBalance && (
| Account |
Debit |
Credit |
{trialBalance.lines.map((line, index) => (
| {line.account_name} |
{line.debit} |
{line.credit} |
))}
| {trialBalance.totals.account_name} |
{trialBalance.totals.debit} |
{trialBalance.totals.credit} |
)}
);
};